JS file operation (ActiveXObject only support IE)
I. Parameter interpretation:
1. FileName:
FileName//file path
2.iomode:
var forreading=1; read-only
var forwriting =2;//Write
var forappending=8;//append
3.create:
true//Create:
false//not created
4.format:
var tristatefalse=0;//opens in ASCII format (default)
VA tristatetrue=-1;//Open in Unicode format
VA tristateusedefault=-2;//opens in system default mode
Two. Write:
1 // Write a file 2 function WriteFile (fileurl,json) {3varnew ActiveXObject (" Scripting.FileSystemObject"); 4 var ts = fso. CreateTextFile (FILEURL, ForWriting,true); 5 ts. Write (JSON); 6 ts. Close (); 7 }
Three. READ:
1 //Read the file2 functionReadFile (FILEURL) {3 varFSO =NewActiveXObject ("Scripting.FileSystemObject");4 varTS = fso. OpenTextFile (Fileurl,forreading,true);5 varjson=ts. ReadAll ();6 ts. Close ();7 returnJSON;8}
JS file operation