国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

Java自動解壓文件實例代碼

2019-11-26 16:10:37
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

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.zip.ZipEntry;
import java.util.zip.ZipFile;


public class UnZipper {

    /**
     * 解壓文件到當前目錄 功能相當于右鍵 選擇解壓
     * @param zipFile
     * @param
     * @author gabriel
     */
    @SuppressWarnings("rawtypes")
    public static void unZipFiles(File zipFile)throws IOException{
        //得到壓縮文件所在目錄
        String path=zipFile.getAbsolutePath();
        path=path.substring(0,path.lastIndexOf("http://"));
       // System.out.println("path "+path);
        ZipFile zip = new ZipFile(zipFile);
        for(Enumeration entries =zip.entries();
                entries.hasMoreElements();){
            ZipEntry entry = (ZipEntry)entries.nextElement();
            String zipEntryName = entry.getName();
            InputStream in = zip.getInputStream(entry);
            //outPath輸出目錄
            String outPath = (path+"http://"+zipEntryName).replaceAll("http://*", "/");;
            //System.out.println("outPath "+outPath);
            //判斷路徑是否存在,不存在則創建文件路徑
            File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
            if(!file.exists()){
                file.mkdirs();
            }
            //判斷文件全路徑是否為文件夾,如果是上面已經上傳,不需要解壓
            if(new File(outPath).isDirectory()){
                continue;
            }
            //輸出文件路徑信息
            System.out.println(outPath);

            OutputStream out = new FileOutputStream(outPath);
            byte[] buf1 = new byte[1024];
            int len;
            while((len=in.read(buf1))>0){
                out.write(buf1,0,len);
            }
            in.close();
            out.close();
            }
        System.out.println("******************解壓完畢********************");
    }

   
    public static void main(String[] args) {
        try {
            unZipFiles(new File("D://all//zip//Default.adiumemoticonset.zip"));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黔东| 达日县| 嘉鱼县| 吴忠市| 吉林省| 平安县| 灌云县| 上饶市| 新安县| 隆德县| 肃南| 南城县| 临湘市| 潞西市| 泸州市| 砀山县| 揭西县| 新安县| 渭南市| 安吉县| 黄陵县| 通山县| 洱源县| 米脂县| 翁牛特旗| 呈贡县| 关岭| 西昌市| 和静县| 彭州市| 湘乡市| 莆田市| 时尚| 兴仁县| 南岸区| 花莲县| 友谊县| 乐业县| 余庆县| 屏边| 铜梁县|