最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java自動(dòng)解壓文件實(shí)例代碼

 更新時(shí)間:2013年04月23日 11:01:55   作者:  
Java自動(dòng)解壓文件實(shí)例代碼,需要的朋友可以參考一下

復(fù)制代碼 代碼如下:

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 {

    /**
     * 解壓文件到當(dāng)前目錄 功能相當(dāng)于右鍵 選擇解壓
     * @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("\\"));
       // 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+"\\"+zipEntryName).replaceAll("\\*", "/");;
            //System.out.println("outPath "+outPath);
            //判斷路徑是否存在,不存在則創(chuàng)建文件路徑
            File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
            if(!file.exists()){
                file.mkdirs();
            }
            //判斷文件全路徑是否為文件夾,如果是上面已經(jīng)上傳,不需要解壓
            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();
        }
    }
}

相關(guān)文章

最新評(píng)論

峡江县| 都安| 汉中市| 疏勒县| 宝兴县| 郁南县| 岗巴县| 普定县| 普宁市| 莆田市| 长岭县| 祥云县| 湖州市| 乳源| 鄯善县| 海丰县| 海宁市| 石嘴山市| 兴海县| 岳阳县| 东乡族自治县| 焦作市| 江孜县| 邵武市| 安塞县| 封开县| 平顺县| 齐河县| 平利县| 花莲市| 开化县| 通城县| 阿克苏市| 当涂县| 乐安县| 泸溪县| 滨州市| 威海市| 日照市| 龙门县| 化隆|