我想将我的数据库文件存储在drawable文件夹中,然后在SD-Card中创建备份。在尝试这样做时,我发现在为drawable文件夹指定的路径中存在问题。我这样做:
尝试{
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
//db = openOrCreateDatabase("demodatabase.sqlite",SQLiteDatabase.CREATE_IF_NECESSARY,null);
currentDBPath = "//drawable//demodatabase.sqlite";
db=openOrCreateDatabase(uri.toString(), 0, null);
System.out.println("====="+ currentDBPath);
backupDBPath = "{demodatabase.sqlite}";
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) {}
提前完成。
答案 0 :(得分:0)
你会把这些文件放在drawable文件夹中,但是放在你的资源文件夹中,只需使用
就可以得到这些文件的输入流context.getAssets().open("demodatabase.sqlite")