|
@@ -170,23 +170,22 @@ public class FileUtil {
|
|
* @param zipSavePath 压缩好的zip包存放路径
|
|
* @param zipSavePath 压缩好的zip包存放路径
|
|
* @param sourceFile 待压缩的文件(单个文件或者整个文件目录)
|
|
* @param sourceFile 待压缩的文件(单个文件或者整个文件目录)
|
|
* @return
|
|
* @return
|
|
- * @Description
|
|
|
|
- * @author xukaixun
|
|
|
|
|
|
+ * @author
|
|
*/
|
|
*/
|
|
public static String zipCompress(String zipSavePath, File sourceFile) {
|
|
public static String zipCompress(String zipSavePath, File sourceFile) {
|
|
try {
|
|
try {
|
|
//创建zip输出流
|
|
//创建zip输出流
|
|
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipSavePath));
|
|
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipSavePath));
|
|
File[] fileList = sourceFile.listFiles();
|
|
File[] fileList = sourceFile.listFiles();
|
|
- if (fileList.length != 0)//如果文件夹为空,则只需在目的地zip文件中写入一个目录进入点
|
|
|
|
- {
|
|
|
|
|
|
+ //如果文件夹为空,则只需在目的地zip文件中写入一个目录进入点
|
|
|
|
+ if (fileList.length != 0) {
|
|
for (File file : fileList) {
|
|
for (File file : fileList) {
|
|
- compress(zos, file, sourceFile.getName() + "/" + file.getName());
|
|
|
|
|
|
+ compress(zos, file, file.getName());
|
|
}
|
|
}
|
|
zos.close();
|
|
zos.close();
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.error("zip compress file exception: {}, zipSavePath={}, sourceFile={}", e, zipSavePath, sourceFile.getName());
|
|
|
|
|
|
+ log.error("压缩文件异常 : {}, zipSavePath={}, sourceFile={}", e, zipSavePath, sourceFile.getName());
|
|
}
|
|
}
|
|
return zipSavePath;
|
|
return zipSavePath;
|
|
}
|
|
}
|