4

I want to get backup installed apk. by using How to get the .apk file of an application programatically and I get the apk File. and when I try to take backup to another file I get

Caused by: java.nio.channels.NonWritableChannelException

code to get backup the file:

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();
     }

I write android.permission.WRITE_EXTERNAL_STORAGE in manifest.xml also.

Community
  • 1
  • 1
Krishna Prasad
  • 693
  • 1
  • 6
  • 19
  • 7
    You are using a **FileInputStream** as the source your `dst` `FileChannel`. Consider trying a **FileOutputStream** instead, it's more likely to open its channel in write mode.. – Jens May 09 '12 at 09:10
  • 1
    @Jens: thank u very much Jens..., u'r really genius... my problem was solved by writting FileOutPutStream to dst. – Krishna Prasad May 09 '12 at 09:16

0 Answers0