Android 安卓数据库超过1MB

Android 安卓数据库超过1MB,android,sqlite,Android,Sqlite,我已经编写了数据库副本。我已经将我的数据库放入asset forder。我的数据库大小为4.5 MB。 如何将数据库分块 package com.xont.db; public class DataBaseMasterHelper extends SQLiteOpenHelper { // The Android's default system path of your application database. private static String DB_PATH =

我已经编写了数据库副本。我已经将我的数据库放入asset forder。我的数据库大小为4.5 MB。 如何将数据库分块

    package com.xont.db;

  public class DataBaseMasterHelper extends SQLiteOpenHelper {

// The Android's default system path of your application database.
private static String DB_PATH = "/data/data/com.xont.controller/databases/";
private static String DB_NAME = "masterventura.db";
private SQLiteDatabase ventura;
private  Context myContext;
private DataBaseHelper myDbHelper;

public DataBaseMasterHelper(Context context) {
    super(context, DB_NAME, null, 1);
    this.myContext = context;
}

/**
 * Creates a empty database on the system and rewrites it with your own
 * database.
 **/
public void createDataBase() throws IOException {
    boolean dbExist = checkDataBase();
    if (dbExist) {
    } else {
        this.getReadableDatabase();
        //this.getReadableDatabase().getPath();
        System.out.println( " ===== " +     this.getReadableDatabase().getPath());
        try {
            copyDataBase();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

public boolean checkDataBase() {
    SQLiteDatabase checkDB = null;
    try {
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null,SQLiteDatabase.OPEN_READONLY);
    } catch (SQLiteException e) {
        e.printStackTrace();
    }

    if (checkDB != null) {
        checkDB.close();
    }

    return checkDB != null ? true : false;
}

private void copyDataBase() throws IOException {
    InputStream myInput = myContext.getAssets().open(DB_NAME);
    String outFileName = DB_PATH + DB_NAME;
    OutputStream myOutput = new FileOutputStream(outFileName);
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
        myOutput.write(buffer, 0, length);
    }
    myOutput.flush();
    myOutput.close();
    myInput.close();


}

public void openDataBase() throws SQLException {
    String myPath = DB_PATH + DB_NAME;
    ventura = SQLiteDatabase.openDatabase(myPath, null,SQLiteDatabase.OPEN_READONLY);

}

@Override
public synchronized void close() {
    if (ventura != null)
        super.close();
        ventura.close();
}

@Override
public void onCreate(SQLiteDatabase db) {
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}

在copyDataBase()方法中,我需要更改代码。如何拆分数据库。请在这方面帮助我


提前感谢…

这里有一篇博客文章,正是您想要的:


我看到的唯一方法是在
copyDataBase()
方法中打开数据库并使用SQL语句处理数据。之后,您可以将其关闭并复制到SD卡。数据库大小可以通过抛出usless垃圾(open Database和iterfere with SQL语句)来分块。该链接对我不起作用,因此我找到了一个存档版本: