try {
File sd = Environment.getExternalStorageDirectory(); //複製到哪裡
File data = Environment.getDataDirectory(); //原始位置
if (sd.canWrite()) {
String currentDBPath = "//data//com.httc.pipeline//xxx.db"; //原始位置檔名
String backupDBPath = "xxx.db"; //複製位置檔名
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
Log.i("currentDB", currentDB+"");
Log.i("backupDB", backupDB+"");
if (currentDB.exists()) { //原始檔案存在
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size()); //開始複製
Log.i("dst", dst+"");
src.close();
dst.close();
}
}
} catch (Exception e) {
Log.i("eDB", e+"");
}
參考來源: http://stackoverflow.com/questions/1995320/how-to-backup-database-file-to-sdcard-on-android
2015年2月25日 星期三
Android db file copy backup 資料庫 檔案 複製 備份
備份資料庫或檔案到其他位置,加入下列程式碼
訂閱:
張貼留言
(
Atom
)
沒有留言 :
張貼留言