[java] 자바에서 압축 파일을 다른 디렉토리로 이동하기

먼저, Java에서는 압축 파일의 이동을 위해 java.util.zip 패키지를 사용할 수 있습니다. 이 패키지를 사용하여 압축 파일을 압축 해제하고, 압축을 해제한 파일들을 원하는 디렉토리로 이동할 수 있습니다.

아래는 Java에서 압축 파일을 압축 해제하고, 압축을 해제한 파일들을 다른 디렉토리로 이동하는 예제 코드입니다.

import java.io.*;
import java.util.zip.*;

public class ZipFileMove {
    public static void main(String[] args) {
        try {
            String sourceFilePath = "path_to_zip_file.zip";
            String destinationDir = "path_to_destination_directory";

            byte[] buffer = new byte[1024];

            ZipInputStream zis = new ZipInputStream(new FileInputStream(sourceFilePath));
            ZipEntry zipEntry = zis.getNextEntry();

            while (zipEntry != null) {
                String fileName = zipEntry.getName();
                File newFile = new File(destinationDir + File.separator + fileName);

                // create all non-existent folders
                new File(newFile.getParent()).mkdirs();

                FileOutputStream fos = new FileOutputStream(newFile);

                int len;
                while ((len = zis.read(buffer)) > 0) {
                    fos.write(buffer, 0, len);
                }

                fos.close();
                zipEntry = zis.getNextEntry();
            }

            zis.closeEntry();
            zis.close();

            System.out.println("압축 파일을 성공적으로 해제하고 이동했습니다.");
        } catch (IOException ex) {
            System.err.println("오류 발생: " + ex.getMessage());
        }
    }
}

위의 예제 코드는 지정된 압축 파일을 압축 해제하고, 압축을 해제한 파일들을 지정된 디렉토리로 이동합니다.

이러한 방식으로 Java를 사용하여 압축 파일을 다른 디렉토리로 이동할 수 있습니다.