2011-04-13 139 views
0

我想将我的数据库文件存储在可绘制的文件夹中,然后在SD卡中创建其备份。虽然试图做到这一点我findind问题在什么路径给予可绘制的文件夹。我这样做:数据库存储和检索

尝试{

 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) {} 

Thanx提前。

回答

0

你会把这些文件不是在绘制文件夹,但在你的资产文件夹,你可以通过使用

context.getAssets().open("demodatabase.sqlite") 
+0

我得到空指针异常得到一个输入流对这些文件的情况下没有采取值...为什么如此?] – Piyush 2011-04-13 12:44:42

+0

您是否使用SQLiteOpenHelper类作为超类? – senola 2011-04-13 12:58:43

+0

不,我只是扩展活动..... – Piyush 2011-04-13 13:04:59

相关问题