Android copy database to mnt/shared -


how can copy database /data/data/my.package.name/databases/ /mnt/shared folder using java?

i tried using fileoutputstream open failed: eacces (permission denied)

use this:

public void writetosdcard() throws ioexception {           system.out.println("write sd");         file f=new file("/data/data/com.yourpackage/databases/dbname");         fileinputstream fis=null;         fileoutputstream fos=null;          try{             fis=new fileinputstream(f);               fos=new fileoutputstream("/mnt/sdcard/dumped.db");             while(true){                 int i=fis.read();                 if(i!=-1){                     fos.write(i);                 }                 else{                     break;                 }             }             fos.flush();          }         catch(exception e){             e.printstacktrace();          }         finally{             try{                 fos.close();                 fis.close();             }             catch(ioexception ioe){                 //      system.out.println(ioe);             }         }          system.out.println("wrote sd");     } 

add required permission in manifest.

<uses-permission android:name="android.permission.write_external_storage" /> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -