复制数据库的代码:
public static final String DB_PATH = Environment.getDataDirectory() + "/data/MyPackageName/databases/";
public static final String DB_NAME = "MyDB.sqlite";
private void copyDataBase(String dbPath){
try{
InputStream inputStream = context.getAssets().open(dbName);
OutputStream appDB = new FileOutputStream(dbPath,false);
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
appDB.write(buffer, 0, length);
}
appDB.flush();
appDB.close();
inputStream.close();
}catch(IOException e){
e.printStackTrace();
}
}
此代码在每个手机和每个 android 版本中都可以正常工作,但我在上面的代码或此行中的某些手机(例如 Galaxy S Plus)中得到了 SQLiteDiskIOException:
SQLiteDatabase db = super.getWritableDatabase();
每个人都可以帮助我解决这个问题吗?