文件夹生成zip

package com.leoodata.utils;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; /**
* User: 杨永生
* Date: 18:03 2018/4/11
* Email: kevin@hiibook.com
*/
public class MkdirsZIP { public static void mkdirsToZIP(String URL) throws IOException {
File file = new File(URL);
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(URL + ".zip"));
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(
files[i]));
zos.putNextEntry(new ZipEntry(file.getName()+ file.separator+ files[i].getName()));
while (true) {
byte[] b = new byte[100];
int len = bis.read(b);
if (len == -1)
break;
zos.write(b, 0, len);
}
bis.close();
}
}
zos.close();
} public static void main(String[] args) {
String url="E:\\HiibookIntellijProject\\svn2\\leoodata\\target\\leoodata\\static\\upload\\report\\2018_04_11_18_32_26_717";
try {
mkdirsToZIP(url);
} catch (IOException e) {
e.printStackTrace();
}
}
}
上一篇:C# 在 vs2010 上开发 ActiveX 控件 【千辛万苦啊~】


下一篇:REST与RESTFul API最佳实践