日期:2014-05-16 浏览次数:20436 次
final String DB_DESTINATION = "/data/data/YOUR_PACKAGE_NAME/databases/MyDatabaseFile.db";?
?
// Check if the database exists before copying?
boolean initialiseDatabase = (new File("DB_DESTINATION")).exists();?
if (initialiseDatabase == true) {?
?
? ? // Open the .db file in your assets directory?
? ? InputStream is = getContext().getAssets().open("MyDatabaseFile.db");?
?
? ? // Copy the database into the destination?
? ? OutputStream os = new FileOutputStream(DB_DESTINATION);?
? ? byte[] buffer = new byte[1024];?
? ? int length;?
? ? while ((length = is.read(buffer)) >