[java] 자바에서 압축 파일명 변경하기
import java.io.*;
import java.util.zip.*;

public class ZipFileRename {
    public static void main(String[] args) {
        String sourceFile = "source.zip";
        String destinationFile = "destination.zip";
        try {
            File file = new File(sourceFile);
            FileInputStream fis = new FileInputStream(file);
            ZipInputStream zis = new ZipInputStream(fis);
            FileOutputStream fos = new FileOutputStream(destinationFile);
            ZipOutputStream zos = new ZipOutputStream(fos);
            ZipEntry ze = zis.getNextEntry();
            while (ze != null) {
                String newFileName = "new_" + ze.getName();
                zos.putNextEntry(new ZipEntry(newFileName));
                byte[] buffer = new byte[1024];
                int len;
                while ((len = zis.read(buffer)) > 0) {
                    zos.write(buffer, 0, len);
                }
                ze = zis.getNextEntry();
            }
            zis.closeEntry();
            zis.close();
            zos.closeEntry();
            zos.close();
            fis.close();
            fos.close();
            System.out.println("압축 파일명 변경이 완료되었습니다.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

위 코드에서, source.zip 파일의 내용을 읽어 destination.zip으로 새로운 압축 파일을 만들고, 각 파일명을 변경하는 예시입니다. 필요에 따라 파일명 변경 로직을 수정하여 사용할 수 있습니다.

참고 자료: