如何使用JavaScript读取和写入文件 [英] How to read and write into file using JavaScript

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

问题描述

任何人都可以提供示例代码来读写使用JavaScript的文件?为了完整性,OP不会状态他正在寻找这样做在浏览器(如果他是,如前所述,这是一般不可能)

然而JavaScript本身确实允许这样做;它可以完成与服务器端JavaScript。



请参阅有关Javascript File class的文档

编辑:这个链接是现在被Oracle移动的Sun文档。

为了跟上这个时代,FileSystem类的node.js文档: a href =http://nodejs.org/docs/latest/api/fs.html =noreferrer> http://nodejs.org/docs/latest/api/fs.html



编辑(2):您现在可以使用HTML5读取客户端文件: http://www.html5rocks.com/en/tutorials/file/dndfiles/


Can anybody give the sample code to read and write the file using 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)

However javascript per se does allow this; it can be done with server side javascript.

See this documentation on the Javascript File class

Edit: That link was to the Sun docs that now have been moved by Oracle.

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): You can read files client side now with HTML5: http://www.html5rocks.com/en/tutorials/file/dndfiles/

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

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