android 代码将数据库文件导出到sd卡


public static void save() {
      String dbpath = "/data/data/tl.cac.view/databases/"
      +"afinal.db";
      boolean success=copyFile(dbpath, Environment.getExternalStorageDirectory() + "/"
      + "afinal.db");
}

public static boolean copyFile(String source, String dest) {
try {
     File f1 = new File(source);
     File f2 = new File(dest);
     InputStream in = new FileInputStream(f1);
     OutputStream out = new FileOutputStream(f2);

     byte[] buf = new byte[1024];
     int len;
     while ((len = in.read(buf)) > 0)
     out.write(buf, 0, len);

     in.close();
     out.close();
} catch (FileNotFoundException ex) {
     return false;
} catch (IOException e) {
     return false;
}
    return true;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM