私のアプリケーションでは、自分のデータベースからデータを読み取る必要があります。私は、「資産」フォルダ内の私のデシベルを置くとパスにアセットからアプリケーションにデータをコピーする際の問題
DB_PATH = "/data/data/com.android.example/databases/"
をコピーするには、次のコードを使用して、しかし、テーブルには、その投げる例外をcreated.Andし、近く強制的に取得されていません。
private void copyDataBase() throws IOException{
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
上記のコードでは、「バッファ」はデータを取得していません。そのため、myOutputにデータを書き込んでいません。私はこのコードをネットで見つけて修正しました。任意の身体は、SDカードに資産フォルダ内のファイルを読むのを助けることができます。私は外部ファイルからSDカードにデータを格納し、そこから読む必要があります。
例外はありますか?ログを添付できますか? – jamapag