android assets文件夹下的数据库应用

来源:互联网 发布:cs231n课程笔记 知乎 编辑:程序博客网 时间:2024/05/16 15:42
//当数据库大于1M时,要用FileSplit工具软件把文件分割成小于1M的小文件// 复制assets下的大数据库文件时用这个private void copyBigDataBase() {File file = new File(DB_PATH);if (file.exists()) {return;}mHandler.sendEmptyMessage(2);try {InputStream myInput;String outFileName = DB_PATH;OutputStream myOutput = new FileOutputStream(outFileName);for (int i = 0; i < 19; i++) {myInput = getAssets().open("joke.db.3h" + i);byte[] buffer = new byte[1024];int length;while ((length = myInput.read(buffer)) > 0) {myOutput.write(buffer, 0, length);}myOutput.flush();myInput.close();System.out.println("copy------>" + i);}myOutput.close();mHandler.sendEmptyMessage(1);} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}