使用javascript进行本地文件访问 [英] Local file access with javascript

查看:115
本文介绍了使用javascript进行本地文件访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有使用JavaScript完成的本地文件操作?我正在寻找一个可以在没有安装空间的情况下完成的解决方案,例如需要AIR。

Is there any local file manipulation that's been done with JavaScript? I'm looking for a solution that can be accomplished with no install footprint like requiring AIR.

具体来说,我想从文件中读取内容并编写这些内容内容到另一个文件。在这一点上,我并不担心获得权限,只是假设我已经拥有对这些文件的完全权限。

Specifically, I'd like to read the contents from a file and write those contents to another file. At this point I'm not worried about gaining permissions, just assuming I already have full permissions to these files.

推荐答案

如果用户通过< input type =file> 选择文件,您可以阅读流程使用文件API 的文件。

If the user selects a file via <input type="file">, you can read and process that file using the File API.

设计不允许读取或写入任意文件。这违反了沙箱。来自维基百科 - > Javascript - >安全

Reading or writing arbitrary files is not allowed by design. It's a violation of the sandbox. From Wikipedia -> Javascript -> Security:


JavaScript和DOM为恶意作者提供
的潜力
提供脚本,通过网络在客户端
计算机上运行。浏览器作者
使用两个
限制包含此风险。首先,脚本在
沙箱中运行,在这个沙盒中他们只能执行
与web相关的操作,而不是
通用编程任务,如
创建文件

2016 UPDATE :可以通过 Filesystem API 仅受Chrome和Opera支持最终没有被其他浏览器实施(使用 Edge的例外)。有关详细信息,请参阅 Kevin的回答

2016 UPDATE: Accessing the filesystem directly is possible via the Filesystem API, which is only supported by Chrome and Opera and may end up not being implemented by other browsers (with the exception of Edge). For details see Kevin's answer.

这篇关于使用javascript进行本地文件访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆