简体   繁体   English

使用html5 FileReader访问本地文件

[英]Access local file with html5 FileReader

I'm trying to make an offline app that reads text from a text file that is stored locally. 我正在尝试创建一个脱机应用程序,从本地存储的文本文件中读取文本。 I understand this is possible with html5 and FileReader. 我理解这可以用html5和FileReader。 I want to hard-code the relative path. 我想硬编码相对路径。 I have read the docs and all them them are based on an array of FileList. 我已经阅读了文档,所有这些文档都基于FileList数组。 But since I am just doing one file with a static path, I can't make sense of it. 但是因为我只是用静态路径做一个文件,所以我无法理解它。 This is silly, I know, but what I have so far: 我知道,这很愚蠢,但到目前为止我还有:

var file = "data/data";
var reader = new FileReader();
reader.readAsText(file);
alert(reader.String);

The FileReader API lets you read files selected by the user in a file input. FileReader API允许您在文件输入中读取用户选择的文件。

It does not let the author of a webpage choose files from their visitor's systems to read. 它不允许网页的作者从其访问者的系统中选择要阅读的文件。 That would be a security risk. 这将是一种安全风险。

This is possible using ActiveX, which isn't too hard to do if you've never worked with it. 这可以使用ActiveX,如果你从未使用它,这不是很难做到的。 Check this out for more info: http://msdn.microsoft.com/en-us/library/2z9ffy99(v=vs.84).aspx 查看更多信息: http//msdn.microsoft.com/en-us/library/2z9ffy99(v = vs。84).aspx

Just means the user will probably have to agree to let ActiveX run.. which admittedly might scare a few away. 只是意味着用户可能不得不同意让ActiveX运行..这无疑可能会吓跑一些。 So it depends upon how much you actually need it. 所以这取决于你实际需要多少。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM