黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 學習攻略 Java學習 Java解壓文件示例

Java解壓文件示例

更新時間:2022-08-18 10:58:45 來源:動力節點 瀏覽1436次

要解壓縮 zip 文件,我們需要讀取 zip 文件,ZipInputStream然后ZipEntry一一讀取。然后使用FileOutputStream將它們寫入文件系統。如果輸出目錄不存在并且 zip 文件中存在任何嵌套目錄,我們還需要創建它。這是解壓之前創建tmp.zip的輸出目錄的java解壓縮文件程序。

package com.journaldev.files;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class UnzipFiles {
    public static void main(String[] args) {
        String zipFilePath = "/Users/pankaj/tmp.zip";        
        String destDir = "/Users/pankaj/output";        
        unzip(zipFilePath, destDir);
    }
    private static void unzip(String zipFilePath, String destDir) {
        File dir = new File(destDir);
        // create output directory if it doesn't exist
        if(!dir.exists()) dir.mkdirs();
        FileInputStream fis;
        //buffer for read and write data to file
        byte[] buffer = new byte[1024];
        try {
            fis = new FileInputStream(zipFilePath);
            ZipInputStream zis = new ZipInputStream(fis);
            ZipEntry ze = zis.getNextEntry();
            while(ze != null){
                String fileName = ze.getName();
                File newFile = new File(destDir + File.separator + fileName);
                System.out.println("Unzipping to "+newFile.getAbsolutePath());
                //create directories for sub directories in zip
                new File(newFile.getParent()).mkdirs();
                FileOutputStream fos = new FileOutputStream(newFile);
                int len;
                while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
                }
                fos.close();
                //close this ZipEntry
                zis.closeEntry();
                ze = zis.getNextEntry();
            }
            //close last ZipEntry
            zis.closeEntry();
            zis.close();
            fis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }        
    }
}

程序完成后,我們在具有相同目錄層次結構的輸出文件夾中擁有所有 zip 文件內容。上述程序的輸出是:

Unzipping to /Users/pankaj/output/.DS_Store
Unzipping to /Users/pankaj/output/data/data.dat
Unzipping to /Users/pankaj/output/data/data.xml
Unzipping to /Users/pankaj/output/data/xmls/project.xml
Unzipping to /Users/pankaj/output/data/xmls/web.xml
Unzipping to /Users/pankaj/output/data.Xml
Unzipping to /Users/pankaj/output/DB.xml
Unzipping to /Users/pankaj/output/item.XML
Unzipping to /Users/pankaj/output/item.xsd
Unzipping to /Users/pankaj/output/ms/data.txt
Unzipping to /Users/pankaj/output/ms/project.doc

 

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 亚洲成综合人影院在院播放 | 欧美黄成人免费网站大全 | 国产精品偷伦视频免费观看的 | 久久精品国产大片免费观看 | 国产精品莉莉欧美自在线线 | 国产精品亚洲国产三区 | 国产1区2区 | 欧美日韩国产高清一区二区三区 | 亚洲欧美二区三区久本道 | 欧美一级片在线播放 | 久久久96| 国产制服丝袜视频 | 站长工具天天爽视频 | 日韩欧美一区二区在线 | 国产a级特黄的片子视频 | 亚洲另类自拍丝袜第1页 | 日韩天天操 | 国产一级特黄高清免费大片dvd | 高级毛片 | 欧美视频在线观看一区二区 | 手机看片高清日韩精品 | 一区二区欧美视频 | 另类黄色 | 色播日韩 | 蜜臀91 | 一本到在线 | 欧美三级香港三级日本三级 | 中国老妇另类xxxx | 三级黄色毛片网站 | 黑人与中国女一级毛片不卡 | 野花影视视频在线观看免费 | 无遮羞无删减肉动漫在线观看 | 日韩三级黄色 | 国产一级特黄a大片免费 | 中文字幕日韩精品中文区 | 夜夜操狠狠操 | 色.com| 一 级 黄 中国色 片 | 天天操天天干天天做 | 中文字幕一区二区精品区 | 午夜免费影视 |