我在onCreate(SQLiteDatabase database)
类中调用SQLiteOpenHelper
时,将具有SQLite数据库结构的文件从资产复制到我的应用程序文件夹中,但是原始文件和复制的文件不是完全等于:
(右侧资产文件夹中的原始文件,左侧复制的文件)
如您所见,只有第一个块不同,文件的其余部分完全相同。
我的onCreate()
方法是:
@Override
public void onCreate(SQLiteDatabase arg0) {
Log.i(TAG, "onCreate");
try {
copyDatabase();
} catch (IOException e) {
e.printStackTrace();
}
}
copyDatabase()
方法是:
private void copyDatabase() throws IOException {
InputStream input = context.getAssets().open(DB_NAME);
String outFilename = DB_PATH;
OutputStream output = new FileOutputStream(outFilename);
byte[] buffer = new byte[1024];
int mLength;
while ((mLength = input.read(buffer)) > 0) {
output.write(buffer, 0, mLength);
}
output.flush();
output.close();
input.close();
}
我不知道为什么我的copyDatabase()
方法在循环的第一次迭代中无法正常工作。
有什么想法吗?