国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
java壓縮解壓代碼
下邊是在項(xiàng)目用到的壓縮解壓class ,粘出來,分享。
 
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import org.apache.commons.lang.StringUtils;
public class ZipTool {
    private static final int BUFFER = 2048;
    private int level;
    public ZipTool() {
        level = 0;
    }
    /**
     * setLevel
     * @param level int
     */
    public void setLevel(int level) {
        this.level = level;
    }
    /**
     * zip a File or Directory
     * @param inputFile File
     * @param outputFile File
     * @throws ZipException
     */
    public void zipFile(File inputFile, File outputFile) throws ZipException {
        try {
            BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(
                outputFile), BUFFER);
            ZipOutputStream out = new ZipOutputStream(bout);
            zip(out, inputFile, inputFile.getName());
            out.close();
        }
        catch (IOException ex) {
            throw new ZipException(ex.getMessage());
        }
    }
    /**
     * zip some Files
     * @param inputFiles File[]
     * @param outputFile File
     * @throws ZipException
     */
    public void zipFiles(File[] inputFiles, File outputFile) throws ZipException {
        try {
            BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(outputFile),
                BUFFER);
            ZipOutputStream out = new ZipOutputStream(bout);
            for (int i = 0; i < inputFiles.length; i++) {
                zip(out, inputFiles[i], inputFiles[i].getName());
            }
            out.close();
        }
        catch (IOException ex) {
            throw new ZipException(ex.getMessage());
        }
    }
    /**
     * unzip a File
     *
     * @param inputFile File
     * @param outputFile File
     * @throws ZipException
     */
    public void unZipFile(File inputFile, File outputFile) throws ZipException {
        try {
            FileInputStream tin = new FileInputStream(inputFile);
            CheckedInputStream cin = new CheckedInputStream(tin, new CRC32());
            BufferedInputStream bufferIn = new BufferedInputStream(cin, BUFFER);
            ZipInputStream in = new ZipInputStream(bufferIn);
            ZipEntry z = in.getNextEntry();
            while (z != null) {
                String name = z.getName();
                if (z.isDirectory()) {
                    File f = new File(outputFile.getPath() + File.separator + name);
                    f.mkdir();
                }
                else {
                    File f = new File(outputFile.getPath() + File.separator + name);
                    f.createNewFile();
                    FileOutputStream out = new FileOutputStream(f);
                    byte data[] = new byte[BUFFER];
                    int b;
                    while ( (b = in.read(data, 0, BUFFER)) != -1) {
                        out.write(data, 0, b);
                    }
                    out.close();
                }
                z = in.getNextEntry();
            }
            in.close();
        }
        catch (IOException ex) {
            throw new ZipException(ex.getMessage());
        }
    }
    private void zip(ZipOutputStream out, File f, String base) throws
        FileNotFoundException, ZipException {
        if (level != 0) {
            out.setLevel(level);
        }
        if (f.isDirectory()) {
            zipDirectory(out, f, base);
        }
        else {
            if (StringUtils.isEmpty(base)) {
                base = f.getName();
            }
            zipLeapFile(out, f, base);
        }
    }
    private void zipDirectory(ZipOutputStream out, File f, String base) throws
        FileNotFoundException, ZipException {
        File[] files = f.listFiles();
        if (level != 0) {
            out.setLevel(level);
        }
        try {
            out.putNextEntry(new ZipEntry(base + "/"));
        }
        catch (IOException ex) {
            throw new ZipException(ex.getMessage());
        }
        if (StringUtils.isEmpty(base)) {
            base = new String();
        }
        else {
            base = base + "/";
        }
        for (int i = 0; i < files.length; i++) {
            zip(out, files[i], base + files[i].getName());
        }
    }
    private void zipLeapFile(ZipOutputStream out, File f, String base) throws
        FileNotFoundException, ZipException {
        if (level != 0) {
            out.setLevel(level);
        }
        try {
            out.putNextEntry(new ZipEntry(base));
            FileInputStream in = new FileInputStream(f);
            BufferedInputStream bufferIn = new BufferedInputStream(in, BUFFER);
            byte[] data = new byte[BUFFER];
            int b;
            while ( (b = bufferIn.read(data, 0, BUFFER)) != -1) {
                out.write(data, 0, b);
            }
            bufferIn.close();
        }
        catch (IOException ex) {
            throw new ZipException(ex.getMessage());
        }
    }
}
 
本文來自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/chfzhb/archive/2008/10/23/3129558.aspx
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
java上傳文件跟批量下載文件
網(wǎng)頁(yè)文檔在線瀏覽(仿百度文庫(kù)設(shè)計(jì))
java實(shí)現(xiàn)zip壓縮文件
如何將文件打成zip包并下載
實(shí)現(xiàn) Android 應(yīng)用在開機(jī)時(shí)自啟動(dòng)
Java 多線程文件拷貝
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服