2011-12-22 42 views
0

我已经创建了一个包含表格的sqlite应用程序。在那个应用程序中,我从表中检索数据。问题是我怎么能加载该应用程序在Android设备与我的数据库。我曾尝试过,但我没有找到答案。在我的应用程序中,我使用了下面的代码。我如何在Android设备中存储数据库?

try{ 
      String destpath = "/data/data/"+getPackageName()+"/database/mmts1.db"; 
      File f = new File(destpath); 
      if(!f.exists()) 
      { 
        copyDb(getResources().getAssets().open("mmts1.db"),new FileOutputStream(destpath)); 
      } 
     } 
     catch(FileNotFoundException e) 
     { 
      Log.e("FileNotFoundException",e.getMessage()); 
     } 
     catch(IOException e) 
     { 
      Log.e("IoException",e.getMessage()); 
     } 

private void copyDb(InputStream open, FileOutputStream fileOutputStream) throws IOException{ 
      // TODO Auto-generated method stub 
      byte [] buffer = new byte[1024]; 
      int length; 
      while((length=open.read(buffer))>0) 
      { 
        fileOutputStream.write(buffer,0,length); 
      } 
      open.close(); 
      fileOutputStream.close(); 

     } 
+0

所以现在你想在真正的Android设备上运行你的应用程序吧? –

回答

相关问题