4

我想备份安装的apk。通过使用如何以编程方式获取应用程序的 .apk 文件,我得到了 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 。

4

0 回答 0