如何使用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文件类的文档
See this documentation on the Javascript File class
编辑:该链接指向现在已被Oracle移动的Sun文档。
Edit: That link was to the Sun docs that now have been moved by Oracle.
为了跟上时间,请参阅FileSystem类的node.js文档:< a href =http://nodejs.org/docs/latest/api/fs.html =noreferrer> 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
编辑(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屋!