簡體   English   中英

XPCOM writeString錯誤

[英]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("\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開發人員此錯誤的含義並找到了它。

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

它解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM