1 回答
TA贡献1820条经验 获得超10个赞
您可以将数据库复制到 SD 卡中,您可以随时从 SD 卡访问数据库
试试这个代码:
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "data/"+sPackageName+"/databases/"+sDBName;
String backupDBPath = "/.appname-external-data-cache/"+sDBName; //"{database name}";
File dir = new File(sd,backupDBPath.replace(sDBName,""));
if(dir.mkdir()) {
}
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
}
} catch (Exception e) {
}
添加回答
举报