我觉得下面的线可能是问题, “window.requestFileSystem(LocalFileSystem.PERSISTENT,0,successCallback,errorCallback)”
在一些我读的帖子,有人提到,requestfilsystem方法以及LocalFileSystem.PERSISTENT参数在Android中不起作用,除非该设备是植根的。
我做了它的工作使用 - “window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory,successCallback,errorCallback);”
如果需要,我可以分享的示例代码中它与文件一起删除目录。请告诉我。希望能帮助到你。
下面是示例代码按要求,
function clearDirectory() {
if (sessionStorage.platform.toLowerCase() == "android") {
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, onFileSystemDirSuccess, fail);
} else {
//for ios
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemDirSuccess, fail);
}
};
function onFileSystemDirSuccess(fileSystem) {
var entry = "";
if (sessionStorage.platform.toLowerCase() == "android") {
entry = fileSystem;
} else {
//for ios
entry = fileSystem.root;
}
entry.getDirectory("Folder_Name", {
create: true,
exclusive: false
},
function(entry) {
entry.removeRecursively(function() {
console.log("Delete successful !!!");
}, fail);
}, getDirFail);
};
function getDirFail(error) {
alert("getDirFail - " + error.code);
};
function fail(error) {
alert("fail - " + error.code);
};
文件创建:
function writeFile() {
if (sessionStorage.platform.toLowerCase() == "android") {
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, onFileSystemSuccess, onError);
} else {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onError);
}
}
function onError(e) {
alert("onError");
};
function onFileSystemSuccess(fileSystem) {
var entry = "";
if (sessionStorage.platform.toLowerCase() == "android") {
entry = fileSystem;
} else {
entry = fileSystem.root;
}
entry.getDirectory("Folder_Name", {
create: true,
exclusive: false
}, onGetDirectorySuccess, onGetDirectoryFail);
};
function onGetDirectorySuccess(dir) {
dir.getFile(filename, {
create: true,
exclusive: false
}, gotFileEntry, errorHandler);
};
function gotFileEntry(fileEntry) {
// logic to write file in respective directory
};
function errorHandler(e) {
// handle error
}
嗨,你可以共享更新的片段删除的文件,而不是文件目录。谢谢 –