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

时间:2021-05-08 17:09:59
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[];
int len;
while ((len = in.read(buf)) > )
out.write(buf, , len); in.close();
out.close();
} catch (FileNotFoundException ex) {
return false;
} catch (IOException e) {
return false;
}
return true;
}