XPCOM writeString error



我使用此函数通过FireFox中的iMacros插件将文本写入文件。

//This function writes string into a file
function WriteFile(path,string)
{
//import FileUtils.jsm
Components.utils.import("resource://gre/modules/FileUtils.jsm");
//declare file
var file = new FileUtils.File(path);
//declare file path
file.initWithPath(path);
//if it exists move on if not create it
if (!file.exists())
{
file.create(file.NORMAL_FILE_TYPE, 0666);
}
var charset = 'EUC-JP';
var fileStream = Components.classes['@mozilla.org/network/file-output-stream;1']
.createInstance(Components.interfaces.nsIFileOutputStream);
fileStream.init(file, 18, 0x200, false);
var converterStream = Components
.classes['@mozilla.org/intl/converter-output-stream;1']
.createInstance(Components.interfaces.nsIConverterOutputStream);
converterStream.init(fileStream, charset, string.length,
Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
//write file to location
converterStream.writeString("rn"+string);
converterStream.close();
fileStream.close();

}

但就昨天而言,无论我尝试了哪种浏览器,还是在不同的电脑上,我都开始收到这条消息。

[Exception... "Component returned failure code: 0x80460003 (NS_ERROR_LOSS_OF_SIGNIFICANT_DATA) [nsIConverterOutputStream.writeString]"  nsresult: "0x80460003 (NS_ERROR_LOSS_OF_SIGNIFICANT_DATA)"  location: "JS frame :: chrome://imacros/content/iMacros.js :: WriteFile :: line 329"  data: no] (Error code: 991)

所以我检查了mozilla开发人员这个错误意味着什么,并发现了这一点。

NS_ERROR_LOSS_OF_SIGNIFICANT_DATA (0x80460003)
NS_ERROR_ILLEGAL_DURING_SHUTDOWN (0x8046001E)
Many operations cannot be performed once the application is being shutdown. This error will occur in this situation.

但我不知道这里的错误是什么,因为我没有以任何方式更改函数代码。有人能解释这个错误吗?

我更换了这个

var charset = 'EUC-JP';

用这个

var charset = 'UTF8';

它解决了我的问题。

最新更新