我正在使用web worker和文件系统api来读取文件的内容。但是,每当我尝试读取该文件时,我都会在var message = read.readAsText(fileEntry)的代码行上获得DOM EXCEPTION 8:NOT FOUND ERROR;任何人都可以帮忙解释为什么会这样吗?
path = e.data + "/" + "index.html";
var buffers = [];
var message = "";
var fileEntry = fs.root.getFile(path, {create: false});
var reader = new FileReaderSync();
message = reader.readAsText(fileEntry);
self.postMessage(message);
答案 0 :(得分:1)
readAsText需要File对象,而不是FileEntrySync对象。调用fileEntry.file()来获取File对象。
path = e.data + "/" + "index.html";
var buffers = [];
var message = "";
var fileEntry = fs.root.getFile(path, {create: false});
var reader = new FileReaderSync();
message = reader.readAsText(fileEntry.file());
self.postMessage(message);