我有这段JavaScript代码无法读取该文件的全部内容在JavaScript
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(this.savefile);
if (file.exists() == false) {
return null;
}
var is = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
is.init(file,0x01, 00004, null);
var sis = Components.classes["@mozilla.org/scriptableinputstream;1"]
.createInstance(Components.interfaces.nsIScriptableInputStream);
sis.init(is);
output = sis.read(sis.available());
sis.close();
is.close();
this.filterData = output;
return output;
的:其实这个我读的文件是一个二进制文件,并让说,350个字节。 现在19字节是“零”,所以会发生什么是在上面的代码中我只得到了18个字节输出。
,当我试图调试sis.available不会返回350.但是sis.read只读取高达零字节。
我想要的方式来读取输出中的整个350字节。
只是要清楚,SAVEFILE是本地的?这是一个Firefox附加组件,对吧? – 2013-02-15 09:26:57
@JonathanFingland对。 – 2013-02-15 09:28:46
这可能是也可能不是相关的,但请参阅https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIScriptableInputStream,其中read()带有警告:如果数据包含空字节,则此方法将返回一个截断的字符串。您可能需要使用readBytes()。 – 2013-02-15 09:34:32