| | |
| | | * @return 成功是/否 |
| | | */ |
| | | public static boolean unzip(String filePath, String zipDir) { |
| | | ZipFile zipFile = null; |
| | | try { |
| | | int count; |
| | | ZipFile zipfile = new ZipFile(filePath); |
| | | zipFile = new ZipFile(filePath); |
| | | |
| | | Enumeration e = zipfile.entries(); |
| | | Enumeration e = zipFile.entries(); |
| | | while (e.hasMoreElements()) { |
| | | ZipEntry entry = (ZipEntry) e.nextElement(); |
| | | if (entry.isDirectory()) { |
| | |
| | | continue; |
| | | } |
| | | |
| | | BufferedInputStream is = new BufferedInputStream(zipfile.getInputStream(entry)); |
| | | BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry)); |
| | | FileOutputStream fos = new FileOutputStream(zipDir + File.separator + entry.getName()); |
| | | BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE); |
| | | |
| | | while ((count = is.read(BUFFER, 0, BUFFER_SIZE)) != -1) { |
| | | dest.write(BUFFER, 0, count); |
| | | } |
| | | |
| | | dest.flush(); |
| | | dest.close(); |
| | | fos.close(); |
| | | is.close(); |
| | | } |
| | | |
| | |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return false; |
| | | } finally { |
| | | try { |
| | | if (null != zipFile) { |
| | | zipFile.close(); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | * @return 成功是/否 |
| | | */ |
| | | public static boolean zip(String zipFile, String sourceDir) { |
| | | FileOutputStream fos = null; |
| | | ZipOutputStream zos = null; |
| | | try { |
| | | FileOutputStream fileOutputStream = new FileOutputStream(zipFile); |
| | | zos = new ZipOutputStream(fileOutputStream); |
| | | fos = new FileOutputStream(zipFile); |
| | | zos = new ZipOutputStream(fos); |
| | | |
| | | File sourceFile = new File(sourceDir); |
| | | compress(sourceFile, zos, sourceFile.getName()); |
| | |
| | | return false; |
| | | } finally { |
| | | try { |
| | | if (zos != null) { |
| | | if (null != zos) { |
| | | zos.close(); |
| | | } |
| | | if (null != fos) { |
| | | fos.close(); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |