Copying a file using Cordova

前端 未结 4 1515
旧时难觅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:47

    The fileEntry.copyTo somehow always gave error, so I tried the fileEntry.moveTo as below, which works well for me in copying any file from the www into say the Library folder of the iOS device.

    function copyToLocation(fileName){       
    console.log("Copying :"+fileName);
        window.resolveLocalFileSystemURL(cordova.file.applicationDirectory+"www/"+fileName,function (fileEntry)
        {
            window.resolveLocalFileSystemURL(cordova.file.dataDirectory,function (directory)
            {                  
               fileEntry.moveTo(directory, 'new_fileName.txt',function(){
                    alert('Successful Copy!');
                },
                function()
                {
                    alert('Copying Unsuccessful ');
                });
            },null);
        }, null);
     }
    

提交回复
热议问题