0
我的問題是,當數據庫從資源文件夾複製到手機的路徑,我的應用總是失敗:加載數據庫 - FileOutputStream中失敗
/data/data/at.atn.android/databases/
我的數據庫名稱:
atnRoutenplaner.sqlite3
我轉讓代碼:
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;
File sampleFile = new File(outFileName);
//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();
}
對不起,沒有工作。我不明白爲什麼。我在atnRoutenplaner.sqlite中使用了一個以前的數據庫。也許這是結局? – user3552619