首页 > Web开发 > 详细

js读写txt文件

时间:2016-11-03 09:31:52      阅读:162      评论:0      收藏:0      [点我收藏+]

 

view plain
<script language="javascript" type="text/javascript">


//读文件
function readFile(filename){
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile(filename,1);
var s = "";
while (!f.AtEndOfStream)
s += f.ReadLine()+"\n";
f.Close();
return s;
}

//写文件
function writeFile(filename,filecontent){
var fso, f, s ;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile(filename,8,true);
f.WriteLine(filecontent);
f.Close();
alert(‘ok‘);
}

</script>
<html>
<input type="text" id="in" name="in" />
<input type="button" value="Write!" onclick="writeFile(‘F:/Appserv/www/12.txt‘,document.getElementByIdx_x(‘in‘).value);"/><br><br>
<input type="button" value="Read!" onclick="document.getElementByIdx_x(‘show‘).value=readFile(‘F:/Appserv/www/12.txt‘);"/><br>
<textarea id="show" name="show" cols="100" rows="20" >
</textarea>
</html>

js读写txt文件

原文:http://www.cnblogs.com/Nicolasap/p/6025196.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!