[英]Can JavaScript read files on the hard drive?
Here I have learned that it is possible with JavaScript in HTML to create files offline and save them on the hard disk. 在这里我了解到可以使用 HTML 中的 JavaScript 离线创建文件并将它们保存在硬盘上。
But what about reading files?但是读取文件呢? Can JavaScript access, say one of my .txt files on my self phone and display the read data (or at least place it in the local storage)?
JavaScript 可以访问,比如我自己手机上的一个 .txt 文件并显示读取的数据(或至少将它放在本地存储中)?
I know that it is possible with PHP, but there is no PHP on my cellphone, while HTML is always there.我知道用 PHP 是可能的,但是我的手机上没有 PHP,而 HTML 总是在那里。
You can use <input type="file">
and FileReader
to read files stored at local filesystem, see File API ;您可以使用
<input type="file">
和FileReader
读取存储在本地文件系统中的文件,请参阅File API ; also How FileReader.readAsText in HTML5 File API works? HTML5 File API 中的 FileReader.readAsText 是如何工作的? .
.
If trying at Chromium or Chrome to read file:
protocol launch the browser with --allow-file-access-from-files
flag, without other Chrome instances running, or use a different --user-data-dir
, see Read local XML with JS .如果尝试在 Chromium 或 Chrome 中读取
file:
协议使用--allow-file-access-from-files
标志启动浏览器,而不运行其他 Chrome 实例,或使用不同的--user-data-dir
,请参阅读取本地 XML与 JS 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.