Android下载压缩文件与解压案例
ackage com.example.jsontest.biz;
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream;
import android.content.Context;
public class DownFile { public static File downLoadFile(Context context,String url) throws MalformedURLException, Exception{ File file=new File(context.getExternalCacheDir()+"downzip.zip"); FileOutputStream out=new FileOutputStream(context.getExternalCacheDir()+"downzip.zip"); URL urlIn=new URL(url); URLConnection conn=urlIn.openConnection(); BufferedInputStream in=new BufferedInputStream(conn.getInputStream()); byte[] bytes=new byte[1024]; while(in.read(bytes)!=-1){ out.write(bytes); } out.flush(); out.close(); return file; } public File Unzip (Context context,File zipFile){ File file=new File(context.getExternalCacheDir()+"downzip.zip"); try { BufferedInputStream bis = new BufferedInputStream(new FileInputStream(zipFile)); ZipInputStream zis = new ZipInputStream(bis); BufferedOutputStream bos = null; ZipEntry entry = null; while ((entry=zis.getNextEntry()) != null) { //String entryName = entry.getName(); bos = new BufferedOutputStream(new FileOutputStream(file)); int b = 0; while ((b = zis.read()) != -1) { bos.write(b); } bos.flush(); bos.close(); } zis.close(); } catch (IOException e) { } return file ; }
}
public class JsonPaser {
public static void paser(File file) throws Exception { StringBuffer stringBuffer = new StringBuffer(); String line = null;
BufferedReader br = new BufferedReader(new FileReader(file)); while ((line = br.readLine()) != null) { stringBuffer.append(line); } // 将Json文件数据形成JSONObject对象 JSONObject jsonObject = new JSONObject(stringBuffer.toString()); // 获取JSONObject对象数据并打印 JSONArray provinces = jsonObject.getJSONArray("*********"); }
}
Android下载压缩文件与解压案例的更多相关文章
- PHP zip压缩文件及解压
PHP zip压缩文件及解压 利用ZipArchive 类实现 只有有函数.界面大家自己写 ZipArchive(PHP 5.3 + 已自带不需要安装dll) /** * 文件解压 * @param ...
- SpringMVC上传压缩文件,解压文件,并检测上传文件中是否有index.html
SpringMVC上传压缩文件,解压文件,并检测上传文件中是否有index.html 说明: 1.环境:SpringMVC+Spring+Tomcat7+JDK1.7 2.支持 zip和rar格式的压 ...
- Android 下载zip压缩文件并解压
网上有很多介绍下载文件或者解压zip文件的文章,但是两者结合的不多,在此记录一下下载zip文件并直接解压的方法. 其实也很简单,就是把下载文件和解压zip文件结合到一起.下面即代码: URLConne ...
- Android之zip文件加密解压及进度条的实现
zip文件的解压能够使用java的zip库,可是没有实现对加密文件的解压功能,这里能够使用zip4j来实现.详细能够參看该文<Android下zip压缩文件加密解密的完美解决方式>.该文件 ...
- Java实现zip压缩文件的解压
需求描述: 前段时间写了一篇博客<Java实现对文本文件MD5加密并ftp传送到远程主机目录>,实现了一部分的业务需求.然而有些业务可能不止传送一个文件,有时候客户需要传多个文件,原有系统 ...
- Unity3D研究院之LZMA压缩文件与解压文件
原地址:http://www.xuanyusong.com/archives/3095 前两天有朋友告诉我Unity的Assetbundle是LZMA压缩的,刚好今天有时间那么就研究研究LZMA.它是 ...
- 【转载】在linux下别用zip 用tar来压缩文件 zip解压后还是utf-8 window10是GBK
3.2 使用 unzip 命令解压缩 zip 文件 将 shiyanlou.zip 解压到当前目录: $ unzip shiyanlou.zip 使用安静模式,将文件解压到指定目录: $ un ...
- pclzip 压缩文件与解压
类PclZip.class.php下载:PclZip.rar<?php header("Content-type: text/html; charset=utf-8"); f ...
- 使用 windows 批处理指令(BAT文件)进行压缩文件(zip)解压操作
以下指令包括文件删除.复制.zip文件解压操作.使用7z指令指令进行解压操作前,需要确保 windows 的 path 系统环境变量中存在7z的安装路径. 7z的下载地址:https://www.7- ...
随机推荐
- c# base和this关键字总结
base:用于在派生类中实现对基类公有或者受保护成员的访问,但是只局限在构造函数.实例方法和实例属性访问器中.MSDN中小结的具体功能包括: (1)调用基类上已被其他方法重写的方法. ( ...
- XPath使用实例
实例 1基本的XPath语法类似于在一个文件系统中定位文件,如果路径以斜线 / 开始, 那么该路径就表示到一个元素的绝对路径 //BBB 选择所有BBB元素 /AAA/CCC 选择 ...
- php : 自定义分页类
Page.class.php : <?php namespace Tools; class Page { private $total; //数据表中总记录数 private $listRows ...
- 使用airbnb的eslint
1. 全局安装eslint npm install -g eslint npm install -g eslint-config-airbnb eslint-plugin-import eslint- ...
- IOS 微信 6.5.2 自动播放音乐 解决方案
之前仅仅是IPhone7\7p 的问题,现在已经扩展到6 .6s.今天在下也行了最新微信,音乐问题果然来了. 好了 下面直接进入正题 首先 引入 <script src="http:/ ...
- system_call中断处理过程
张雨梅 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-10000 1.给menuos添加命令 改 ...
- Babel 学习
一,为了更明白地使用Babel, 先了解Babel 的发展过程. 现在Babel的版本是6, 相对于以前的版本, 它做了重大更新: 1, 模块化:所有的内部组件都变成了单独的包.打开Babel在Git ...
- Python_Day10_进程、线程、协程
本节内容 操作系统发展史介绍 进程.与线程区别 python GIL全局解释器锁 线程 语法 join 线程锁之Lock\Rlock\ ...
- sublime jsx 格式化工具
1.到Sublime Text 3\Packages\ 目录下 git clone https://github.com/ionutvmi/sublime-jsfmt jsfmt 2.重启sublim ...
- java数据库连接池技术原理(浅析)
在执行数据库SQL语句时,我们先要进行数据连接:而每次创建新的数据库的连接要消耗大量的资源,这样,大家就想出了数据库连接池技术.它的原理是,在运行过程中,同时打开着一定数量的数据库连接,形成数据连接池 ...