首页 > 系统 > Android > 正文

Android编程实现将压缩数据库文件拷贝到安装目录的方法

2019-10-24 20:35:34
字体:
来源:转载
供稿:网友

这篇文章主要介绍了Android编程实现将压缩数据库文件拷贝到安装目录的方法,涉及Android处理压缩文件的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了Android编程实现将压缩数据库文件拷贝到安装目录的方法。分享给大家供大家参考,具体如下:

 

 
  1. public void copyZip2DataDirectory(Context context) throws IOException { 
  2. FileOutputStream outputStream = null
  3. AssetManager assetManager = context.getAssets(); 
  4. InputStream inputStream = assetManager.open("test.zip"); 
  5. ZipInputStream zis = new ZipInputStream(inputStream); 
  6. ZipEntry entry = null
  7. while ((entry = zis.getNextEntry()) != null) { 
  8. outputStream = context.openFileOutput(entry.getName(), Context.MODE_PRIVATE); 
  9. byte[] buffer = new byte[2 * 1024]; 
  10. int len = -1; 
  11. while ((len = zis.read(buffer)) != -1) { 
  12. outputStream.write(buffer, 0, len); 
  13. outputStream.close(); 
  14. zis.close(); 
  15. inputStream.close(); 

希望本文所述对大家Android程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表