阅读:1718回复:0
xul文件调用js,js调用txt,txt中文呈现乱码。
js保存为utf-8编码或在xul调用js时,加上charset="GB2312"能正常显示js上的中文,但不能正常显示js调用的txt的中文,无论txt是什么编码。
不知道如何能正常显示txt的中文, 调用的其中一段编码是 function hcib_loadIntroText() { // get intro.txt file var introTextFile; introTextFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); introTextFile.initWithPath(globalStorage['hcibrowser'].fileIntroPath); // open and read based on read from Lemur log toolbar code var istream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); istream.init(introTextFile, 0x01, 0444, 0); istream.QueryInterface(Components.interfaces.nsILineInputStream); globalStorage['hcibrowser'].introText = ""; var line = {}; var hasmore; do { hasmore = istream.readLine(line); globalStorage['hcibrowser'].introText = globalStorage['hcibrowser'].introText + line.value + "\n"; } while (hasmore); istream.close(); //alert("introText = " + globalStorage['hcibrowser'].introText) } 注:txt文件的路径前面已经确定好了。 |
|