如何将文件复制到cordva中的另一个目录?

问题描述:

我已经将复制文件的代码写入到一个位置到另一个位置,但是它会抛出未知的错误,并且在运行在andriod中时也面临着nullPointerException。任何人都请解释我。 这里我的代码下面如何将文件复制到cordva中的另一个目录?

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, successCallback, errorCallback) 
        function successCallback(filesystem) { 
         alert("2"); 
         filesystem.root.getDirectory('mservice', {create:false}, function(fileEntry) {alert("3"); 
          fileEntry.getFile('queue_mgr.txt',{create:false},function(file){alert("4"); 
          var filePath = "/Download/queue_mgr.txt"; 
          alert(filePath); 
          var name ='queue_mgr.txt'; 
          parentEntry =new DirectoryEntry(name,filePath); 
          //alert(parentEntry.name); 
          alert(parentEntry); 
           file.copyTo(parentEntry,'queue_mgr.txt',function(e){alert("success"+e.fullPath);},function(er){alert("fail"+er.code);}); 
          },errorCallback); 
         },errorCallback); 
        } 
        function errorCallback(error) { 
         alert("ERROR: " + error.code); 
        } 

System.err的:在org.apache.cordova.file.FileUtils.transferTo(FileUtils.java:784) 11-14 21:41:29.785 32161-32229/COM。 example.database W/System.err的:在org.apache.cordova.file.FileUtils.access $ 1300(FileUtils.java:56) 11-14 21:41:29.785 32161-32229/com.example.database W /系统.ERR:在org.apache.cordova.file.FileUtils $ 21.run(FileUtils.java:510) 11-14 21:41:29.785 32161-32229/com.example.database W/System.err的:在有机apache.cordova.file.FileUtils $ 25.run(FileUtils.java:657) 11-14 21:41:29.785 32161-32229/com.example.database W/System.err的:在java.util.concurrent.ThreadPoolExecutor中。 runWorker(ThreadP oolExecutor.java:1112) 11-14 21:41:29.785 32161-32229/com.example.database W/System.err的:在java.util.concurrent.ThreadPoolExecutor中$ Worker.run(ThreadPoolExecutor.java:587) 11-14 21:41:29.795 32161-32229/com.example.database W/System.err的:在java.lang.Thread.run(Thread.java:841)

这里的源:https://github.com/apache/cordova-plugin-file/blob/master/src/android/FileUtils.java

它看起来像你在FileNotFoundException?通过在代码中添加更多的异常处理,可能更容易分辨出它的失败。


编辑:异常是从一个内部方法TransferTo(),这是从在file.copyTo()围绕线称为未来515的方法,正在寻找几个值,其中一个或多个的显示为空 - 因此您的例外:

if (srcURLstr == null || destURLstr == null) { 
     // either no source or no destination provided 
     throw new FileNotFoundException(); 
    } 

检查,以确保传递到file.copyTo()源和目标PARAMS是有效的URL字符串,而不是空。

+0

我不能得到任何clarifications.plz帮我出this.i寻觅了lot.but我没有得到任何成功 –