我使用此助手,并且工作正常:
public class DBHelper extends SQLiteOpenHelper{private final static String DB_PATH = "/data/data/[YOUR PACKAGE HERE]/databases/";String dbName;Context context;File dbFile;public DBHelper(Context context, String dbName, CursorFactory factory, int version) { super(context, dbName, factory, version); this.context = context; this.dbName = dbName; dbFile= new File(DB_PATH + dbName);}@Overridepublic synchronized SQLiteDatabase getWritableDatabase() { if(!dbFile.exists()){ SQLiteDatabase db = super.getWritableDatabase(); copyDatabase(db.getPath()); } return super.getWritableDatabase();}@Overridepublic synchronized SQLiteDatabase getReadableDatabase() { if(!dbFile.exists()){ SQLiteDatabase db = super.getReadableDatabase(); copyDatabase(db.getPath()); } return super.getReadableDatabase();}@Overridepublic void onCreate(SQLiteDatabase db) {}@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}private void copyDatabase(String dbPath){ try{ InputStream assestDB = context.getAssets().open("databases/"+dbName); OutputStream appDB = new FileOutputStream(dbPath,false); byte[] buffer = new byte[1024]; int length; while ((length = assestDB.read(buffer)) > 0) { appDB.write(buffer, 0, length); } appDB.flush(); appDB.close(); assestDB.close(); }catch(IOException e){ e.printStackTrace(); }}}考虑到数据库的文件扩展名是 .db ,并且我的数据库位于 资产/数据库/



