我搜索并尝试了很多东西,只是为了使用 resolveLocalFileSystemURL 检索任何路径的文件的内容
该文件位于:storage/emulated/0/miniclipld.txt
但我无法访问它,尝试过:
window.resolveLocalFileSystemURL('file:///storage/emulated/0/miniclipld.txt', function(fileEntry){
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
console.log(this.result); // text
};
reader.readAsText(file);
});
}, function(err){
console.error(err);
//error
});
Run Code Online (Sandbox Code Playgroud)
太努力了
window.resolveLocalFileSystemURL('/storage/emulated/0/miniclipld.txt', function(fileEntry){
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
console.log(this.result); // text
};
reader.readAsText(file);
});
}, function(err){
console.error(err);
//error
});
Run Code Online (Sandbox Code Playgroud)
无论如何,返回的代码是 1 或 5,是文件路径不正确还是什么?任何帮助表示赞赏!
问题只是在 filaname 中的一个错字...以下结构是正确的。如果有人想知道如何从 android 中的任何路径读取文件,请使用以下代码
window.resolveLocalFileSystemURL('file:///storage/emulated/0/miniclipId.txt', gotFile, fail);
function fail(e) {
console.log("FileSystem Error");
console.dir(e);
}
function gotFile(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
var content = this.result;
console.log(content);
};
reader.readAsText(file);
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3722 次 |
| 最近记录: |