[java] 자바에서 압축 파일 내 특정 파일의 압축 일자 가져오기

먼저, ZipFile 클래스를 사용하여 압축 파일을 엽니다. 그런 다음, getEntry 메서드를 사용하여 특정 파일의 ZipEntry 객체를 얻습니다. 최종적으로 ZipEntry 객체의 getTime 메서드를 사용하여 압축 일자를 가져옵니다.

다음은 이러한 과정을 보다 구체적으로 보여주는 예제 코드입니다.

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class ZipFileExample {
    public static void main(String[] args) {
        try {
            File zipFile = new File("path/to/your/zipfile.zip");
            ZipFile zip = new ZipFile(zipFile);
            ZipEntry entry = zip.getEntry("path/within/zipfile/file.txt");

            if (entry != null) {
                long lastModifiedTime = entry.getTime();
                System.out.println("압축 일자: " + lastModifiedTime);
            } else {
                System.out.println("파일을 찾을 수 없습니다.");
            }

            zip.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

위 예제 코드에서 “path/to/your/zipfile.zip”은 압축 파일의 경로를, “path/within/zipfile/file.txt”는 압축 파일 내의 특정 파일의 경로를 나타냅니다. 이러한 경로를 해당하는 실제 경로로 변경하여 사용하시면 됩니다.

이를 통해 자바에서 압축 파일 내 특정 파일의 압축 일자를 가져올 수 있습니다.