1
var data = "";
Components.utils.import("resource://gre/modules/NetUtil.jsm");
NetUtil.asyncFetch(filename, function(inputStream, status) {
if (!Components.isSuccessCode(status)) {
error("Error reading file. Details:\n" + status);
return;
}
// The file data is contained within inputStream.
// You can read it into a string with
data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
});
我:
Error: uncaught exception: [Exception... "Must have a channel and a callback" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: chrome://myapp/content/js/utils.js :: readFile :: line 234" data: no]
線234是指:
NetUtil.asyncFetch(filename, function(inputStream, status) {
而且this other example使用IO XPCOM,這是不可用的,我在哪裏可以找到它?
是否有一種簡單的方法來讀取Xul中單行文本的文件?