1. /** 
  2.  * 数据库复制 
  3.  *  
  4.  * @param dataBasePath:数据库路径 例如"/data/data/com.my.jarDatabase/databases/"
  5. * @param dbName :数据库名字  ctx :上下文对象 
  6.  * @return 编辑历史 2012-8-16 
  7.  */ 
  8. public void copyDataBase( String   dataBasePath,String dbName,Context ctx) throws IOException { 
  9.     String databaseFilenames = dataBasePath + dbName; 
  10.     File dir = new File(dataBasePath); 
  11.     if (!dir.exists()) 
  12.         dir.mkdir(); 
  13.     FileOutputStream os = null
  14.     try { 
  15.         os = new FileOutputStream(databaseFilenames);  
  16.     } catch (FileNotFoundException e) { 
  17.         e.printStackTrace(); 
  18.     } 
  19.     InputStream is = ctx.getAssets().open(dbName);//获取assets文件夹下的db资源(不能大于1M) 
  20.     byte[] buffer = new byte[8192]; 
  21.     int count = 0
  22.     try { 
  23.         while ((count = is.read(buffer)) > 0) { 
  24.             os.write(buffer, 0, count); 
  25.             Log.i("data", "copying......"); 
  26.             os.flush(); 
  27.         } 
  28.     } catch (IOException e) { 
  29.  
  30.         Log.e("error", e.toString()); 
  31.     } 
  32.     try { 
  33.         is.close(); 
  34.         os.close(); 
  35.     } catch (IOException e) { 
  36.         e.printStackTrace(); 
  37.     }