- /**
- * 数据库复制
- *
- * @param dataBasePath:数据库路径 例如"/data/data/com.my.jarDatabase/databases/"
- * @param dbName :数据库名字 ctx :上下文对象
- * @return 编辑历史 2012-8-16
- */
- public void copyDataBase( String dataBasePath,String dbName,Context ctx) throws IOException {
- String databaseFilenames = dataBasePath + dbName;
- File dir = new File(dataBasePath);
- if (!dir.exists())
- dir.mkdir();
- FileOutputStream os = null;
- try {
- os = new FileOutputStream(databaseFilenames);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- InputStream is = ctx.getAssets().open(dbName);//获取assets文件夹下的db资源(不能大于1M)
- byte[] buffer = new byte[8192];
- int count = 0;
- try {
- while ((count = is.read(buffer)) > 0) {
- os.write(buffer, 0, count);
- Log.i("data", "copying......");
- os.flush();
- }
- } catch (IOException e) {
- Log.e("error", e.toString());
- }
- try {
- is.close();
- os.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }