public class DBManager { private SQLiteDatabase db; Context context; public static final String DB_NAME = "atf.db"; public DBManager(Context context){ this.context=context; db=DBManagerS("com.cosber.wse.atf"); }
//把assets目录下的db文件复制到dbpath下 public SQLiteDatabase DBManagerS(String packName) { String dbPath = "/data/data/" + packName + "/databases/" + DB_NAME; if (!new File(dbPath).exists()) { try { FileOutputStream out = new FileOutputStream(dbPath); InputStream in = context.getAssets().open(DB_NAME); byte[] buffer = new byte[1024]; int readBytes = 0; while ((readBytes = in.read(buffer)) != -1) out.write(buffer, 0, readBytes); in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } return SQLiteDatabase.openOrCreateDatabase(dbPath, null); }}