• 解压zip文件


      import java.io.File;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.InputStream;
      import java.io.OutputStream;
      import java.util.Enumeration;
      import java.util.Map;


      import org.apache.tools.zip.ZipEntry;
      import org.apache.tools.zip.ZipFile;

      import com.google.common.base.Strings;
      import com.winway.fullmoni.dataplug.cache.FileServerPath;
      import com.winway.wcloud.datacontact.eception.ResourceResult;
      import com.winway.wcloud.datacontact.sso.LoginResult;
      import com.winway.wcloud.dbcore.dao.IDAO;
      import com.winway.wcloud.httpaction.annotation.Action;
      import com.winway.wcloud.httpaction.base.BaseController;
      import com.winway.wcloud.httpbase.NanoHTTPD.IHTTPSession;
      import com.winway.wcloud.httpbase.NanoHTTPD.Response;
      import com.winway.wcloud.httpbase.ResponseHelper;
      import com.winway.wcloud.unity.util.StringUtil;
      import com.winway.wcloud.unity.util.ZipUtils;



    public static void main(String[] args){ long start=System.currentTimeMillis(); Calskdfj cj=new Calskdfj(); cj.unzip("E:\apache-tomcat-7.0.70.zip","E:\apache-tomcat"); String f="E:\apache-tomcat-7.0.70"; long end=System.currentTimeMillis(); System.out.println("执行时间:"+(end-start)); File file=new File(f); String[] test=file.list(); for(int i=0;i<test.length;i++){ System.out.println(test[i]); } System.out.println("-----------------------------"); String filename=""; File[] tempList=file.listFiles(); for(int k=0;k<tempList.length;k++){ if(tempList[k].isFile()){ System.out.println("文 件"+tempList[k]); filename=tempList[k].getName(); System.out.println("文件名:"+filename); } if(tempList[k].isDirectory()){ System.out.println("文件夹:"+tempList[k]); } } } /** * 解压zip文件 * @param path 文件的路径 * @param savepath 要保存的路径,可以为空,则是为zip文件名为路径 */ public void unzip(String path,String savepath){ File file=null; InputStream is=null; OutputStream os=null; BufferedOutputStream bos=null; if(Strings.isNullOrEmpty(savepath)){ savepath=path.substring(0,path.lastIndexOf('.'))+File.separator; }else{ if(!new File(savepath).isDirectory()&&savepath.lastIndexOf('/')>0){ savepath=savepath.substring(0, savepath.lastIndexOf('/')); }else{ savepath=savepath+File.separator; } } ZipFile zipFile=null; file=new File(savepath); if(!file.exists())file.mkdir(); try { zipFile=new ZipFile(new File(path), "gbk"); Enumeration<?> enerits=zipFile.getEntries(); while(enerits.hasMoreElements()){ ZipEntry entry=(ZipEntry) enerits.nextElement(); String filename=entry.getName(); boolean ismkdir=false; if(filename.lastIndexOf('/')>0){ ismkdir=true; } filename=savepath+filename; file=new File(filename); if(entry.isDirectory()){ file.mkdir(); continue; } if(ismkdir){ new File(filename.substring(0, filename.lastIndexOf("/"))).mkdir(); } file.createNewFile(); is=zipFile.getInputStream(entry); os=new FileOutputStream(file); bos=new BufferedOutputStream(os); byte[] buf=new byte[buffer]; int count=-1; while((count=is.read(buf))!=-1){ bos.write(buf, 0, count); } bos.flush(); os.close(); is.close(); } zipFile.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { try { if(bos!=null) bos.close(); if(os!=null) os.close(); if(is!=null) is.close(); if(zipFile!=null) zipFile.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
  • 相关阅读:
    PAT顶级 1002. Business (35)
    Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister
    Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market
    主席树模板poj 2104
    Java 集合相关
    扁平疣病治疗
    一些网址
    在ubuntu14.04设置静态ip
    在Ubuntu14.04下安装vsftp服务器
    移植SDL运行库到Tiny6410 上
  • 原文地址:https://www.cnblogs.com/gym2017/p/7479033.html
Copyright © 2020-2023  润新知