我想在android中使用ORMLite預先存在的數據庫文件。我有已經創建數據庫的database.db文件。我想在我的應用程序中使用它。如何使用ORMLite將預先存在的數據庫讀入Android
我的課程擴展了OrmLiteSqliteOpenHelper。
任何人都有想法嗎?請幫助
我使用的數據庫文件複製到使用
公共靜態無效copyDataBase(字符串路徑,上下文C)數據路徑拋出IOException異常{
//Open your local db as the input stream
InputStream myInput = c.getAssets().open("Mydb.db");
// Path to the just created empty db
String outFileName = "/data/data/packageName/databases/databaseName";
String outFileName2 = "/data/data/packageName/databases/";
File file = new File(outFileName2);
if(!file.exists())
file.mkdirs();
//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();
}
,但它不會幫助我。
那你試試,到目前爲止,並沒有你會得到什麼錯誤? – Qben