我有2个字符串。希望所有人首先制作一个.txt文件,然后将字符串保存为unicode。
function WriteFile(file, str, str2)
{
var tmp=real_url.replace(/%20/g, " ");
var WshNetwork=new ActiveXObject("WScript.Network");
var userid=WshNetwork.UserName;
var fso = new ActiveXObject("Scripting.FileSystemObject");
if(! fso.FolderExists(tmp+"users/"+userid))
{
var cf = fso.CreateFolder(tmp+"users/"+userid);
}
else
{
//alert("THIS FOLDER ALREADY EXISTS");
}
delete fso;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.OpenTextFile(tmp+"users/"+userid+"/"+file, 2, true);
fh.WriteLine(str);
fh.WriteLine(str2);
fh.Close();
delete fso;
return;
}
我
答案 0 :(得分:2)
CreateTextFile和OpenTextFile方法都有一个指定编码的参数(ASCII或Unicode(UTF16LE))
var fso = new ActiveXObject("Scripting.FileSystemObject");
var filename = "c:\\testfile.txt";
var f = fso.OpenTextFile(filename, 2, true, -1); // -1 means unicode
f.WriteLine("Hello world!");
f.Close();