日期:2014-05-16  浏览次数:20456 次

javascript对文件的操作

javascript 读文件

?

<script language="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; 
}

alert(readFile("c:\\abc.txt"));
</script>

?

javascript写文件

<script language="javascript">
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'); 
}
writeFile('c:/1234.txt','ffffff');
</script>

?

javascript删除文件:

<script language="javascript">
var fso, f1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1 = fso.GetFile("c:\\1234.txt");
f1.Delete();// 删除文件
alert("ok");

</script>

?

javascript创建一个文件

<script language="javascript">
var fso;// 创建FileSystemObject对象实例
fso = new ActiveXObject("Scripting.FileSystemObject");// 获取Drive 对象
fso.CreateFolder ("C:\\chenchunxia22o");// 创建新文件夹
</script>

?

??