如果要用网页做一个客户端的程序(无后台),那么就要能对文件系统进行操作。想实现的功能如下:参数配置对象转换成json字符串保存到文件系统, 从文件系统读取字符串转换成json对象。
CreateTextFile(FileName, Overwrite, Unicode)
OpenTextFile(FileName, IOMode, Create, Format)
var fso = new ActiveXObject("Scripting.FileSystemObject"); //加载控件
var path = "C:\\Users\\gaohu\\Desktop\\新建文件夹\\a.txt";
function readFile(fso,path){
var f1 = fso.GetFile(path);
var fh = fso.OpenTextFile(f1, 1/*reading*/);
var content = '';
while ( !fh.AtEndOfStream ) {
content += fh.ReadLine();
}
fh.close();
return JSON.parse(content);
}
function writeFile(fso,path){
var a = [{"person1":{
"name":"abc",
"age":10
}},{"person2":{
"name":"cde",
"age":20
}}];
var str = JSON.stringify(a);
newFile = fso.CreateTextFile(path, true);
newFile.WriteLine(str);
newFile.close();
}