阅读与科尔多瓦(resolveLocalFileSystemURL)内部存储文件的Android
问题描述:
我已经搜索并尝试了很多东西只能用resolveLocalFileSystemURL阅读与科尔多瓦(resolveLocalFileSystemURL)内部存储文件的Android
该文件位于检索任何路径的文件的内容:存储/模拟/ 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
});
也试过
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
});
无论如何,返回的代码是1或5,是文件路径不正确或什么?任何帮助感谢!
答
这个问题只是一个拼写错误...下面的结构是正确的。如果有人想知道如何从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);
});
}
谢谢 - 我节省了很多时间试图解决这个Android的错误 - 我在前面加上“文件://”来在Android中fileURI - window.resolveLocalFileSystemURL(“file://”+ fileURI,成功,失败),它解决了我的问题。 – Paul