XPCOM writeString错误

问题描述:

我使用这个功能,将文本写入通过在Firefox的iMacros插件的文件。XPCOM writeString错误

//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("\r\n"+string); 
converterStream.close(); 
fileStream.close(); 


} 

至于昨天,我开始收到此消息,无论哪个浏览器我尝试和不同的PC上。

[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 developers检查这个错误是什么意思,并发现这一点。

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'; 

,它解决了我的问题。