[java] 자바에서 압축 해제 시 압축된 파일의 속성 가져오기
import java.io.*;
import java.util.zip.*;
public class ZipFileProperties {
public static void main(String[] args) {
try {
String zipFilePath = "example.zip";
ZipFile zipFile = new ZipFile(zipFilePath);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
System.out.println("File name: " + entry.getName());
System.out.println("Compressed size: " + entry.getCompressedSize());
System.out.println("Uncompressed size: " + entry.getSize());
System.out.println("Last modified time: " + entry.getLastModifiedTime());
System.out.println("CRC value: " + entry.getCrc());
System.out.println("------------------------");
}
zipFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
위의 예제 코드는 “example.zip”라는 압축 파일의 속성을 읽어와 출력하는 방법을 보여줍니다. 이 코드는 java.util.zip.ZipFile 및 java.util.zip.ZipEntry 클래스를 사용하여 압축 파일의 속성을 가져옵니다. 위의 코드를 실행하면 압축 파일 내의 각 파일의 속성을 콘솔에 출력할 수 있습니다.
더 자세한 내용은 Java 8 공식 문서를 참조하십시오.