「java」ZipEntryでファイルを圧縮するコード

Javaコード
public static void zipDIR(String srcDir, String destZipFile) {
try {
FileOutputStream target = new FileOutputStream(destZipFile);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(target));
int BUFFER_SIZE = 1024;
byte buff[] = new byte[BUFFER_SIZE];
File dir = new File(srcDir);
if (!dir.isDirectory()) {
throw new IllegalArgumentException(srcDir+" はディレクトリではありません!");
}
File files[] = dir.listFiles();
for (int i = 0; i < files.length; i++) {
FileInputStream fi = new FileInputStream(files[i]);
BufferedInputStream origin = new BufferedInputStream(fi);
ZipEntry entry = new ZipEntry(files[i].getName());
out.putNextEntry(entry);
int count;
while ((count = origin.read(buff)) != -1) {
out.write(buff, 0, count);
}
origin.close();
}
out.close();
} catch (IOException e) {
throw new MsgException(“");
}
}

Java

Posted by arkgame