Created
April 27, 2014 06:38
-
-
Save codeachange/11338995 to your computer and use it in GitHub Desktop.
android copy sqlite database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File dbPath = getDatabasePath("taobaoclient.db"); | |
if (!dbPath.exists()) { | |
try { | |
InputStream is = getAssets().open("databases/taobaoclient.db"); | |
int size = is.available(); | |
byte[] buffer = new byte[size]; | |
is.read(buffer); | |
is.close(); | |
FileOutputStream fos = new FileOutputStream(dbPath); | |
fos.write(buffer); | |
fos.close(); | |
}catch (Exception e){ | |
Log.e("Fck", e.getMessage()); | |
} | |
} | |
try{ | |
db = SQLiteDatabase.openDatabase(dbPath.getAbsolutePath(), null, SQLiteDatabase.OPEN_READWRITE); | |
}catch(Exception e){ | |
Log.e("fck", e.getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment