我正在使用 Phonegap 1.4.1 和 Sencha 编写一个下载和读取 pdf 文件的 Android 应用程序。如何使用 phonegap 方法、javascript 或 ajax 检查文件是否存在于电话目录中?
最佳答案
我遇到了同样的问题。我无法让 Darkaico 的答案起作用,但有了 Kurt 的答案,我可以让它起作用。
这是我的代码:
function checkIfFileExists(path){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
fileSystem.root.getFile(path, { create: false }, fileExists, fileDoesNotExist);
}, getFSFail); //of requestFileSystem
}
function fileExists(fileEntry){
alert("File " + fileEntry.fullPath + " exists!");
}
function fileDoesNotExist(){
alert("file does not exist");
}
function getFSFail(evt) {
console.log(evt.target.error.code);
}
那么你只需要这样执行:
checkIfFileExists("path/to/my/file.txt");
关于javascript - 如何使用phonegap检查电话目录中的文件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10294166/