尝试获取备份apk文件时java.nio.channels.NonWritableChannelException

时间:2012-05-09 07:28:55

标签: android

我想获得备份安装apk。通过使用H ow to get the .apk file of an application programatically,我得到了apk文件。当我尝试将备份带到另一个文件时,我得到了

Caused by: java.nio.channels.NonWritableChannelException

备份文件的代码:

File sourceFile = new File(app.publicSourceDir);
File backupFile = new File(Environment.getExternalStorageDirectory(), "SoundRecorder.apk");
if(!backupFile.exists())
     backupFile.createNewFile();
     if(sourceFile.exists()) {
         FileChannel src = new FileInputStream(sourceFile).getChannel();
         FileChannel dst = new FileInputStream(backupFile).getChannel();
         dst.transferFrom(src, 0, src.size());  <--here I get the exception
         src.close();
         dst.close();
     }

我也在manifest.xml中写了android.permission.WRITE_EXTERNAL_STORAGE。

0 个答案:

没有答案