我已經看到了幾個不同的示例,說明如何使用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