如何使用 JavaScript 读取和写入文件? [英] How to read and write into file using JavaScript?
问题描述
谁能提供一些示例代码来使用 JavaScript 读取和写入文件?
Can anybody give some sample code to read and write a file using JavaScript?
推荐答案
为完整起见,OP 没有说明他希望在浏览器中执行此操作(如果他是,正如已经说明的那样,通常是不可能的)
For completeness, the OP does not state he is looking to do this in a browser (if he is, as has been stated, it is generally not possible)
然而,javascript 本身确实允许这样做;它可以通过服务器端 javascript 来完成.
However javascript per se does allow this; it can be done with server side javascript.
请参阅此 有关 Javascript 文件类的文档
编辑:该链接指向现在已由 Oracle 移动的 Sun 文档.
Edit: That link was to the Sun docs that now have been moved by Oracle.
为了跟上时代的步伐,这里是 FileSystem 类的 node.js 文档:http://nodejs.org/docs/latest/api/fs.html
To keep up with the times here's the node.js documentation for the FileSystem class: http://nodejs.org/docs/latest/api/fs.html
Edit(2):您现在可以使用 HTML5 读取文件客户端:http://www.html5rocks.com/en/tutorials/file/dndfiles/
Edit(2): You can read files client side now with HTML5: http://www.html5rocks.com/en/tutorials/file/dndfiles/
这篇关于如何使用 JavaScript 读取和写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!