/**
* 解压文件到指定路径
*
* @param filePath
* @param upZipPath
* @return 返回解压的文件集合
*/
public static List<File> unZip(String filePath, String upZipPath) {
List<File> list = new ArrayList<File>();
int count = -1;
File file = null;
InputStream is = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null;
// 生成指定的保存目录
String savePath = upZipPath;
if (!new File(savePath).exists()) {
new File(savePath).mkdirs();
}
try {
ZipFile zipFile = new ZipFile(filePath, "GBK");
Enumeration enu = zipFile.getEntries();
while (enu.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntry) enu.nextElement();
if (zipEntry.isDirectory()) {
new File(savePath + "/" + zipEntry.getName()).mkdirs();
continue;
}
if (zipEntry.getName().indexOf("/") != -1) {
new File(savePath
+ "/"
+ zipEntry.getName().substring(0,
zipEntry.getName().lastIndexOf("/")))
.mkdirs();
}
is = zipFile.getInputStream(zipEntry);
file = new File(savePath + "/" + zipEntry.getName());
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos, BUFFER);
byte buf[] = new byte[BUFFER];
while ((count = is.read(buf)) > -1) {
bos.write(buf, 0, count);
}
bos.flush();
fos.close();
is.close();
list.add(file);
}
zipFile.close();
return list;
} catch (IOException ioe) {
log.error(ioe.getMessage());
return list;
}
}