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

 

posted @ 2018-05-29 11:50  星辰之力  阅读(1445)  评论(0编辑  收藏  举报