sanxuan85
小狐狸
小狐狸
  • UID32661
  • 注册日期2010-04-25
  • 最后登录2010-04-26
  • 发帖数1
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
阅读:1718回复:0

xul文件调用js,js调用txt,txt中文呈现乱码。

楼主#
更多 发布于:2010-04-25 11:01
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文件的路径前面已经确定好了。
游客

返回顶部