public static boolean compress(File file, String path) {
ZipOutputStream out = null;
FileInputStream in = null;
try {
out = new ZipOutputStream(new FileOutputStream(path));
in = new FileInputStream(file);
out.putNextEntry(new ZipEntry(file.getName()));
byte[] buf = new byte[ConstantUtil.BUFFER];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} catch (Exception e) {
return false;
} finally {
if (null != out) {
try {
out.closeEntry();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != in) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return true;
}
String xmlPath = StringUtil.FILE_PATH.replaceAll("file:", "") + "upload/" + xml;
String zipPath = StringUtil.FILE_PATH.replaceAll("file:", "") + "upload/" + zip;
File file = new File(xmlPath);
UploadFileUtil.compress(file, zipPath);