JScript 操作文本文件 练习代码

小风风的博客 / 2023-08-16 / 原文

 

var TextStream = function () {
this.handle = null;
this.create = function (filename, overwrite) {

var fso = new ActiveXObject("scripting.filesystemobject");
this.handle = fso.CreateTextFile(filename, overwrite);
}
this.open = function(filename){
var fso = new ActiveXObject("scripting.filesystemobject");
this.handle = fso.OpenText(filename, overwrite);
}
this.write = function (data) { return this.handle.WriteLine(data); }
this.close = function () { return this.handle.Close();}
};



var file = new TextStream();
file.create("c:\\test.txt", true);
file.write("中文啊。。。");

txt.close();