I'm copying a file with the structure of my SQLite database from the assets into my application folder when onCreate(SQLiteDatabase database)
is called in the SQLiteOpenHelper
class, but the original file and the copied one are not exactly equals:
(Original file from the assets folder at the right, copied one at the left)
As you can see, only the first block is different, and the rest of the file is exactly the same.
My onCreate()
method is:
@Override
public void onCreate(SQLiteDatabase arg0) {
Log.i(TAG, "onCreate");
try {
copyDatabase();
} catch (IOException e) {
e.printStackTrace();
}
}
And the copyDatabase()
method is:
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();
}
I have no idea why my copyDatabase()
method is not working properly in, I guess, in the first iteration of the loop.
Any idea?