/**
* 压缩目录
*/
public static void createZip(final String dir, final String zipFile) throws IOException {
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
Files.walkFileTree(Paths.get(dir), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
zos.putNextEntry(new ZipEntry(path.toString()));
//zos.putNextEntry(new ZipEntry(path.toString().replace("d:\\", "")));
zos.write(Files.readAllBytes(path));
return FileVisitResult.CONTINUE;
}
});
zos.close();
}
网友评论