首页 > 移动平台 > 详细

Android下载压缩文件与解压案例

时间:2014-04-12 00:45:33      阅读:523      评论:0      收藏:0      [点我收藏+]

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下载压缩文件与解压案例,布布扣,bubuko.com

Android下载压缩文件与解压案例

原文:http://www.cnblogs.com/linyu-03-28/p/3658532.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!