我正在使用此功能通过 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.
但是我无法弄清楚这里的错误是什么,因为我没有以任何方式更改功能代码。有人可以解释这个错误吗?