Copying a file using Cordova

前端 未结 4 1464
旧时难觅i
旧时难觅i 2021-01-19 03:21

I\'ve been trying to copy file named versions.txt from applicationDirectory to externalApplicationStorageDirectory using cordova but code fails.

here is the code

4条回答
  •  终归单人心
    2021-01-19 03:53

    Served my source code to the PhoneGap developer app. My file copy code is below.

       //COPY FILE
       var wwwDirEntry;
    
       //resolve url for directory entry for putting in copied file
       window.resolveLocalFileSystemURL(cordova.file.dataDirectory+'phonegapdevapp/www/', function success(dirEntry) {
           wwwDirEntry = dirEntry;
       });
    
       //resolve file URL to file entry to enable copying
       //
       //Desired URL: file:///data/user/0/com.adobe.phonegap.app/files/phonegapdevapp/www/my_awesome_file.doc
       //BASE URL: cordova.file.dataDirectory / file:///data/user/0/com.adobe.phonegap.app/files/
       //
       //alert(JSON.stringify(cordova.file.dataDirectory));
       //
       window.resolveLocalFileSystemURL(cordova.file.dataDirectory+'phonegapdevapp/www/my_awesome_file.doc',
          function onSuccess(fileEntry)
          {
              //alert(JSON.stringify(fileEntry));
              fileEntry.copyTo(wwwDirEntry, 'a_copy_of_my_awesome_file.doc',
              function()
              {
                  alert('copying was successful');
              },
              function()
              {
                  alert('copying FAILED');
              });
         }, function (e) { alert(JSON.stringify(e)); });
    

提交回复
热议问题