0
私はいくつかのデータを収集し、それらをデスクトップ上のファイルに保存するfirefox拡張を開発しました。Firefox 4の拡張file.createUnique例外:NS_ERROR_FAILURE
Mac OSではうまく動作しますが、Windows 7ではファイル作成時にエラーが発生します。 例外:
uncaught exception:[Exception... "Component returned failure code:0x80004005(NS_ERROR_FAILURE)[nsIFile.createUnique]" nsresult:"0x80004005 (NS_ERROR_FAILURE)" location: "JS frame::chrome://klmlogger/content/record.js :: <TOP_LEVEL> :: line 59" data: no]
コードはここにある:
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("Desk", Components.interfaces.nsIFile);
file.append("samplefile.txt");
file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666); // Line 59
私はライン59を削除し(そしてそれはまだマックOS上で動作する)場合は、エラーになった:
Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIFileOutputStream.init]
resource://gre/modules/FileUtils.jsm Line: 86
エラーここに現れる:
if (modeFlags === undefined)
modeFlags = this.MODE_WRONLY | this.MODE_CREATE | this.MODE_TRUNCATE;
fos.init(file, modeFlags, this.PERMS_FILE, 0); // Line 86
return fos;
ファイルがすでに存在する場合は、コードが正常に動作します。しかし、私の場合は、ファイルを動的に作成する必要があります。そして私が得ることができる有用なエラーメッセージはもうありません。 – Sheng