环境:Android
在应用程序中,我在 "/data/data/com.my.app/changes/123456789/123456789.json"位置创建了一个文件
我已经使用自定义 cordova android 插件交叉检查该文件是否存在。
当尝试使用 cordova File api 访问此文件时,如下所示。 api 根本无法提供 1000 个代码。
var path = "/changes/123456789/123456789.json"
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSystem){
console.log('in got FS');
fileSystem.root.getFile(path,{create:true, exclusive: false},
function(fileEntry){
console.log('gotFileEntry');
},
function(err){
console.log('gotFileEntry fail');
console.log('err.code');
console.log(err.code);
}
);
},
function(){
console.log('fail');
}
);
我收到错误代码“1000”,我认为是“找不到文件”。
根据新插件文档,文件路径应该相对于文件系统根目录。 我认为问题在于我传递文件路径的方式。
在 iOS 设备上测试时同样有效,问题仅出现在 ANDROID 上。
请让我知道我到底哪里出了问题。因为我完全卡住了。 非常感谢任何帮助。
提前致谢。
最佳答案
经过大量挖掘,您好Cordova file api在post的帮助下, 能够访问 ANDROID 中的文件。
用过
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) {
console.log("got main dir",dir);
dir.getFile("log.txt", {create:true}, function(file) {
console.log("got the file", file);
});
});
获取Android中的文件入口。这也适用于 iOS。
关于android - Cordova 文件 api : getFile issue in android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26888957/