我已经看到了几个不同的示例,说明如何使用Phonegap File API将文件从一个目录复制到另一个目录,但是无法将文件从我的应用程序文件夹复制到根目录中的现有文件夹。 File API文档非常模糊,我一直在应用程序目录中找不到文件。将文件从应用程序文件夹复制到JQM/Phonegap App中的根文件夹?
我可以访问SD卡根文件夹文件:/// storage/emulated/0 /使用root.toURL()并读写它,我似乎无法访问我的应用程序文件夹。
Phonegap构建配置文件的权限。
<gap:plugin name="org.apache.cordova.file" version="1.3.1" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root" />
任何帮助或例子会很好。
感谢,
RG
wwwPath = cordova.file.applicationDirectory;
var fp = "temp/myfile.txt";
var fileDestPath = "tempFolder/";
function copyFile(){
var basePath = wwwPath+fp;
window.resolveLocalFileSystemURL(basePath, function(fileEntry){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
var copyToPath = fileSystem.root.toURL()+fileDestPath;
fileEntry.copyTo(copyToPath, 'newFileName.txt', function(){
alert("file copy success");
},fileCopyFail);
},fileCopyFail);
},fileCopyFail);
function fileCopyFail(error) {
alert(error);
}
感谢回复迈克。现在,只是试图让android工作。我正在使用file.applicationDirectory,但不能解决文件URL。 API没有提供任何有关如何从应用程序文件夹复制到外部根目录的实例。任何机会你有一些代码?我会发布我一直在努力的工作。 – BGecko