java中怎么获得压缩文件的大小?需要获得压缩包里的每个文件的大小,求各位帮忙

2024-12-01 07:35:52
推荐回答(1个)
回答1:

import java.io.*;
import java.util.zip.*;
/**
 * @author Hardneedl
 */
public class ZipEntriesDemo {
    public static void main(String... args) throws IOException {
        ZipInputStream zipIn = new ZipInputStream(new FileInputStream(args[0]));
        ZipEntry zipEntry;
        while ( (zipEntry = zipIn.getNextEntry()) != null ) {
            zipIn.closeEntry();
            if (!zipEntry.isDirectory()) {
                String name = zipEntry.getName();
                long size = zipEntry.getSize();
                long compd = zipEntry.getCompressedSize();
                System.out.printf("%s , size=%d, compressed size=%d\r\n", name, size, compd);
            }
        }
        zipIn.close();
    }
}