简体   繁体   English

如何从本地文件读取字符串?

[英]How can i read string from local file?

How can i read files by specifying "file path" by using javascript? 如何通过使用javascript指定“文件路径”来读取文件?

i am lazy to manually click input button and select them every times. 我很懒于手动单击输入按钮并每次选择它们。

i also tried to cheat it by use JQUERY to do but it seems like jquery can not modified input value. 我也试图通过使用JQUERY来作弊,但似乎jquery无法修改输入值。

Any other suggestion to dealing with local file is welcome. 欢迎处理本地文件的任何其他建议。 Thank you 谢谢

For security reasons javascript is running in a sandbox environment inside the browser and you cannot access the file system on the client computer. 出于安全原因,javascript在浏览器内部的沙箱环境中运行,并且您无法访问客户端计算机上的文件系统。

If that was possible by only navigating to a website, the author of this website could access any file on the client computer. 如果仅通过导航到某个网站是可能的,则该网站的作者可以访问客户端计算机上的任何文件。 That's not something that people browsing the internet usually want. 那不是人们浏览互联网通常想要的东西。


UPDATE: 更新:

Using the HTML5 File API you have the possibility to access the contents on the client of files that were explicitly loaded by the user in an <input type="file"> fields or were for example drag and dropped from the desktop. 使用HTML5 File API,您可以访问客户端在<input type="file">字段中明确加载的<input type="file">或从桌面拖放的<input type="file">的内容。 But the user must explicitly perform this action. 但是用户必须明确执行此操作。 You cannot access arbitrary files. 您不能访问任意文件。

How can i read files by specifying "file path" by using javascript? 如何通过使用javascript指定“文件路径”来读取文件?

You can't. 你不能

i am lazy to manually click input button and select them every times. 我很懒于手动单击输入按钮并每次选择它们。

You have to. 你必须。 That is how the user gives the web application permission to access the files. 这就是用户授予Web应用程序访问文件权限的方式。

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

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