使用手机间隙构建的文件api,我想获得应该存储所有文件的应用程序目录。
我需要使用什么命令?
答案 0 :(得分:4)
function gotFS(fileSystem) {
console.log("got filesystem");
// save the file system for later access
console.log(fileSystem.root.fullPath);
window.rootFS = fileSystem.root;
}
document.addEventListener('deviceready', function() {
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}, false);
使用此代码,您将拥有一个DirectoryEntry对象,用于存储在全局变量" rootFS"中的应用程序的根目录。您可以像这样获取该文件夹的路径:
rootFS.fullPath
答案 1 :(得分:3)
您可以使用cordova.file.applicationDirectory获取您的app目录。 它会解决 文件:/// android_asset /在android和 /var/mobile/Applications//.app/ in IOS
您可以在android和iOS中的www目录中获取所有应用文件。
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory+'www/index.html',success,fail);
function success(fileEntry){
console.log("got the file object")
}
function fail(error){
console.log("error");
}
用于获取存储应用程序文件的文件系统上的app目录,可以通过cordova.file.applicationStorageDirectory获取 其中包含两个目录文件,缓存都是持久的。
您可以查看链接以获取更多详细信息..
https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md