Skip to content

Instantly share code, notes, and snippets.

@n0m0r3pa1n
Last active August 29, 2015 14:19
Show Gist options
  • Save n0m0r3pa1n/cc09d3b931f010ee0ccf to your computer and use it in GitHub Desktop.
Save n0m0r3pa1n/cc09d3b931f010ee0ccf to your computer and use it in GitHub Desktop.
private static final String DATABASE_NAME = "BGHISTORY_v3";
private static final String DATABASE_PATH = "/data/data/com.nmp90.bghistory/databases/";
private void copyDataBase() throws IOException {
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DATABASE_NAME);
// Path to the just created empty db
String outFileName = DATABASE_PATH + DATABASE_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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment