gpt4 book ai didi

java - Phonegap Cordova 删除文件 (android)

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:50:43 25 4
gpt4 key购买 nike

你好..

我是 phonegap 的新手..

我在 android phonegap 3.4 中删除文件时遇到问题

console.log(photo);    

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
photo, {create: false},
function gotFileEntry(fileEntry) {
fileEntry.remove();
},
onError);
},
onError);

记录结果

04-24 16:29:54.234: I/Web 控制台 (16213): file:///storage/sdcard0/DCIM/Camera/1398331773136.jpg

04-24 16:49:01.989: W/System.err(18864): org.apache.cordova.file.EncodingException: 此路径中包含无效的“:”。

04-24 16:49:01.994: W/System.err(18864): 在 org.apache.cordova.file.LocalFilesystem.getFileForLocalURL(LocalFilesystem.java:159)

04-24 16:49:01.994: W/System.err(18864): 在 org.apache.cordova.file.FileUtils.getFile(FileUtils.java:698)

04-24 16:49:03.664: I/Web 控制台 (18864): 5

经过搜索,我在文档中得到了这个(错误代码和含义列表)

5 = 编码错误

文件路径是否错误以及如何获取 sdcard 中文件的有效路径?

谢谢

最佳答案

我认为您的问题出在调用回调函数的方式上。这段代码对我有用:

console.log("remove file");
var relativeFilePath = "MyDir/file_name.png";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
fileSystem.root.getFile(relativeFilePath, {create:false}, function(fileEntry){
fileEntry.remove(function(file){
console.log("File removed!");
},function(){
console.log("error deleting the file " + error.code);
});
},function(){
console.log("file does not exist");
});
},function(evt){
console.log(evt.target.error.code);
});

关于java - Phonegap Cordova 删除文件 (android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23265704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com