Javascript,写入txt文件另存为UNICODE [英] Javascript, write to txt file save as UNICODE
本文介绍了Javascript,写入txt文件另存为UNICODE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个字符串。希望所有这些都首先创建一个.txt文件,然后将字符串另存为Unicode。
I have 2 strings. Would like it all to first make a .txt file and then save the strings to it as 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;
}
I
推荐答案
CreateTextFile 和 OpenTextFile 方法有一个指定编码的参数(ASCII或Unicode(UTF16LE))
Both the CreateTextFile and OpenTextFile methods have a parameter that specify the encoding (ASCII or 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();
这篇关于Javascript,写入txt文件另存为UNICODE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文