2011-12-22 5 views
0

私はテーブルを含むsqliteアプリケーションを作成しました。そのアプリケーションでは、私はテーブルからデータを取得しました。問題は、どうやって私のデータベースでアンドロイドデバイスにそのアプリケーションをロードできるかということです。私は試しましたが、答えが見つかりませんでした。私のアプリケーションで私は以下のコードを使用しています。どのように私はアンドロイドデバイスにデータベースを格納できますか?

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搭載端末でアプリケーションを実行したいのですか? –

答えて

1

SQLiteAssetHelperを使用してアプリケーションにデータベースをパッケージ化します。

+0

ありがとうございます。 sqliteassethelperが私のアプリケーションで動作しています...ありがとう。 – NareshRavva

関連する問題