用JavaScript从硬盘读取文件 [英] Reading files from hard drive with javascript

查看:151
本文介绍了用JavaScript从硬盘读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序创建 .xml 文件并将它们存储在用户的硬盘上;我在 web.xml 中设置了一个默认文件夹来存储这些文件,比如 D:/ temp 。现在,我写的文件,我需要读回他们与JavaScript,我正在使用一个JavaScript库,有这个功能 mxUtils.load('文件的URL')(这个函数返回文件的内容),问题是它给我一个错误跨源请求只支持HTTP ,(我现在没有与函数或库有关的任何东西)我认为问题在于,由于某些安全问题,您无法读取本地文件。任何人都可以告诉我一些解决方案?谢谢

解决方案

您不能使用javascript访问本地文件系统。
要使用JavaScript访问文件,您必须将其上传到服务器,然后使用文件url访问它。


My application creates .xml files and stores them on the user's hard drive; there is a default folder that I set in the web.xml to store the files, let's say D:/temp. Now after I write the files I need to read them back with javascript, I am using a javascript library that has this function mxUtils.load('URL of the file') (this function returns the content of the file), the problem is that it is giving me an error Cross origin requests are only supported for HTTP, (I now it doesn't have anything to do with the function or the library) I think the problem is that you can't read local files because of some security issues. Anyone can advise me some solution? Thanks

解决方案

You cant access local filesystem using javascript. For accessing the file using javascript , you have to upload it to a server and access it using the files url.

这篇关于用JavaScript从硬盘读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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