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下载压缩文件与解压案例的更多相关文章

  1. PHP zip压缩文件及解压

    PHP zip压缩文件及解压 利用ZipArchive 类实现 只有有函数.界面大家自己写 ZipArchive(PHP 5.3 + 已自带不需要安装dll) /** * 文件解压 * @param ...

  2. SpringMVC上传压缩文件,解压文件,并检测上传文件中是否有index.html

    SpringMVC上传压缩文件,解压文件,并检测上传文件中是否有index.html 说明: 1.环境:SpringMVC+Spring+Tomcat7+JDK1.7 2.支持 zip和rar格式的压 ...

  3. Android 下载zip压缩文件并解压

    网上有很多介绍下载文件或者解压zip文件的文章,但是两者结合的不多,在此记录一下下载zip文件并直接解压的方法. 其实也很简单,就是把下载文件和解压zip文件结合到一起.下面即代码: URLConne ...

  4. Android之zip文件加密解压及进度条的实现

    zip文件的解压能够使用java的zip库,可是没有实现对加密文件的解压功能,这里能够使用zip4j来实现.详细能够參看该文<Android下zip压缩文件加密解密的完美解决方式>.该文件 ...

  5. Java实现zip压缩文件的解压

    需求描述: 前段时间写了一篇博客<Java实现对文本文件MD5加密并ftp传送到远程主机目录>,实现了一部分的业务需求.然而有些业务可能不止传送一个文件,有时候客户需要传多个文件,原有系统 ...

  6. Unity3D研究院之LZMA压缩文件与解压文件

    原地址:http://www.xuanyusong.com/archives/3095 前两天有朋友告诉我Unity的Assetbundle是LZMA压缩的,刚好今天有时间那么就研究研究LZMA.它是 ...

  7. 【转载】在linux下别用zip 用tar来压缩文件 zip解压后还是utf-8 window10是GBK

    3.2 使用 unzip 命令解压缩 zip 文件 将 shiyanlou.zip 解压到当前目录:   $ unzip shiyanlou.zip 使用安静模式,将文件解压到指定目录:   $ un ...

  8. pclzip 压缩文件与解压

    类PclZip.class.php下载:PclZip.rar<?php header("Content-type: text/html; charset=utf-8"); f ...

  9. 使用 windows 批处理指令(BAT文件)进行压缩文件(zip)解压操作

    以下指令包括文件删除.复制.zip文件解压操作.使用7z指令指令进行解压操作前,需要确保 windows 的 path 系统环境变量中存在7z的安装路径. 7z的下载地址:https://www.7- ...

随机推荐

  1. Python之路,Day1 - Python基础1

    本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...

  2. Object-C

    #import <Foundation/Foundation.h> #pragma mark 狗类的声明 @interface Dog:NSObject { @public NSStrin ...

  3. 文本数据源Fields Format

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  4. 浅析word-break work-wrap区别

    word-break:[断词] 定义:规定自动换行的处理方法.   注:通过word-break使用,可以实现让浏览器在任意位置换行. 语法:word-break: normal|break-all| ...

  5. Cocos2d-x 核心概念 - Node(节点)与Node层级架构

    Cocos2d-x采用层级结构管理场景 层 精灵 等节点(Node)对象 一个场景包含了多个层,一个层又包含多个对象 层级结构中的节点(Node)可以是场景,精灵等任何对象 节点的层级结构 Scene ...

  6. Ubuntu 12.04 Virtualbox 启用USB 设备支持

    转载自:http://www.cnblogs.com/ericsun/archive/2013/06/10/3130679.html 具体步骤在上面的链接中 今天在ubuntu下安装了Virtualb ...

  7. img的空白符

    在div里面嵌套了一个img出来问题,div的高度超过了img的高度,大约3px ,查看了样式没什么问题,后来百度了一下,找到了2种的方法都有效: 第一种:img{display:block} 第二种 ...

  8. AC自动机小结

    专题链接 第一题--hdu2222 Keywords Search ac自动机的模板题,入门题.  题解 第二题--hdu2896 病毒侵袭   一类病毒的入门题,类似模板  题解 第三题--hdu3 ...

  9. WPF界面布局——各种控件

    Grid是最常用的动态布局控件,也是所有动态布局控件中唯一可按比例动态调整分配空间的控件. label : 标签,用来显示文本内容.可以为其他控件如文本框等添加一些描述性的信息. TextBox : ...

  10. SQL Tuning / SQL 性能 优化 调优

    Some key concents regarding SQL optimization predicate selectivity (column unique ratio) / cardinali ...