有人可以提供一些示例代码来使用JavaScript读写文件吗?
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)
(为了完整起见,OP并未声明他正在浏览器中进行此操作(如前所述,如果不可能,通常是不可能的))
However javascript per se does allow this;
(但是javascript本身允许这样做;)
(可以使用服务器端javascript来完成。)
See this documentation on the Javascript File class
( 请参阅 Javascript File类上的此 文档 )
Edit : That link was to the Sun docs that now have been moved by Oracle.
(编辑 :该链接指向Oracle现在已移动的Sun文档。)
To keep up with the times here's the node.js documentation for the FileSystem class: http://nodejs.org/docs/latest/api/fs.html
(为了与时俱进,这里是FileSystem类的node.js文档: http : //nodejs.org/docs/latest/api/fs.html)
Edit(2) : You can read files client side now with HTML5: http://www.html5rocks.com/en/tutorials/file/dndfiles/
(Edit(2) :您现在可以使用HTML5在客户端读取文件: http : //www.html5rocks.com/zh-CN/tutorials/file/dndfiles/)
1.4m articles
1.4m replys
5 comments
57.0k users