怎么利用js读取txt文件

要能打开文件并能显示

js读取txt文件:

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;
}

js写txt文件:

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');
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-02-15
js能读txt文件还得了,那互联网就没有安全性可言了,
js不允许读取用户磁盘数据。
相似回答