<!DOCTYPE?html>
<html>
<head>
<meta?charset="UTF-8">
<title>Document</title>
<script>
function?file(){
var?fso,ts,s;
var?ForReading=1;
try{
fso=new?ActiveXObject("Scripting.FileSystemObject");
}catch(e){
alert("當(dāng)前瀏覽器不支持!");
return;
}?
alert("已執(zhí)行方法2");
//生成隨機(jī)數(shù)組aa
function?randomFn(){
return?Math.floor(Math.random()*10);
}
var?arr=[];
for(var?i=0;i<10;i++){
var?aa=randomFn();
arr.push(aa);
}
//創(chuàng)建文件
var?f1=fso.createtextfile("D:\實(shí)習(xí)代碼\\lianxices\\a.txt",true);
//寫入文件,我看的代碼都是在這里直接寫入內(nèi)容?,我不知道怎么把數(shù)組放進(jìn)去,求大佬說(shuō)一下?????
f1.WriteLine("?");
f1.Close();
ts=fso.OpenTextFile("D:\實(shí)習(xí)代碼\\lianxices\\a.txt",ForReading);
s=ts.ReadLine();
alert("File?contents"+s+"");
}
</script>
</head>
<button?onclick="file()">創(chuàng)建一個(gè)文本文件</button>
<body>
</body>
</html>C語(yǔ)言Java可以生成文件并讀取內(nèi)容,我發(fā)現(xiàn)js只有在ie下用ActiveXObject可以生成本地文件 ,擼個(gè)代碼寫著玩,可以在f.writeline()里寫入內(nèi)容 但是不知道怎么把數(shù)組放進(jìn)去或者是別的內(nèi)容,謝謝了
js在IE下創(chuàng)建本地文件,并讀取內(nèi)容
哎呀呀哎呦呦
2017-10-13 17:13:03