zoukankan      html  css  js  c++  java
  • zip包的解压

    public static void unzip1(String zipName, String temPath) throws IOException {
    		ZipFile zip = new ZipFile(new File(zipName),Charset.forName("UTF-8"));
    		String zipName1 = zip.getName().substring(zip.getName().lastIndexOf("\") + 1, zip.getName().lastIndexOf("."));
    		System.out.println(zipName1);
    		String temp = temPath + "/" + zipName1 + System.currentTimeMillis();
    		File filePath = new File(temp);
    		if (!filePath.exists()) {
    			filePath.mkdirs();
    		}
    		
    		for (Enumeration<ZipEntry> zipEntrys = (Enumeration<ZipEntry>) zip.entries(); zipEntrys.hasMoreElements();) {
    			ZipEntry entry = zipEntrys.nextElement();
    			String name = entry.getName();
    			 System.out.println(name);
    			InputStream is = zip.getInputStream(entry);
    			String outputPath = (temp + "/" + name).replaceAll("\*", "/");
    			//判断文件路径是否存在
    			File file = new File(outputPath.substring(0, outputPath.lastIndexOf("/")));
    			if (!file.exists()) {
    				file.mkdirs();
    			}
    			
    			if (new File(outputPath).isDirectory()) {
    				continue;
    			}
    			
    			FileOutputStream os = new FileOutputStream(outputPath);
    			byte[] buf = new byte[1024]; 
    			int len = 0;
    			while((len = is.read(buf)) != -1) {
    				os.write(buf, 0, len);
    			}
    			os.close();
    			is.close();
    		}
    		System.out.println("解压成功。。。。");
    	}
    	
    	public static void main(String[] args) {
    		String dir = "E:/test";
    		String zipName = "E:/test/zhangsan.zip";
    		String tempPath = "E:/zip";
    //		unzip(dir, zipName, tempPath);
    		File file = new File(zipName);
    		try {
    //			unZipFiles(file, tempPath);
    			
    //			unzip1(zipName, tempPath);
    			System.out.println(invertOrder(123569));
    		} catch (Exception e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    

      

  • 相关阅读:
    GIS Cesium地图数据配置
    HDFS详解
    Hadoop学习路线图
    SecureCRT工具
    Eclipse使用技巧收集
    如何确定 Hadoop map和reduce的个数--map和reduce数量之间的关系是什么?
    HBase基本概念
    Hbase Rowkey设计
    MapReduce调度与执行原理系列文章
    LVS学习笔记及总结(思维导图版)
  • 原文地址:https://www.cnblogs.com/wangxiaowang/p/7818792.html
Copyright © 2011-2022 走看看