导入已有数据库
- /**
- * Created by Owen Chan
- * On 2017-09-26.
- */
- public class DbManager {
- public static final String PACKAGE_NAME = "com.example.sql";
- public static final String DB_NAME = "table.db";
- public static final String DB_PATH = "/data/data/" + PACKAGE_NAME;
- private Context mContext;
- public DbManager(Context mContext) {
- this.mContext = mContext;
- }
- public SQLiteDatabase openDataBase() {
- return SQLiteDatabase.openOrCreateDatabase(DB_PATH + "/" + DB_NAME, null);
- }
- public void importDB() {
- File file = new File(DB_PATH + "/" + DB_NAME);
- if (!file.exists()) {
- try {
- FileOutputStream out = new FileOutputStream(file);
- int buffer = 1024;
- InputStream in = mContext.getResources().openRawResource(R.raw.xxxx);
- byte[] bts = new byte[buffer];
- int lenght;
- while ((lenght = in.read(bts)) > 0) {
- out.write(bts, 0, bts.length);
- }
- out.close();
- in.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
(编辑:西安站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|