- public static String mmUnzip(String pSource, String pPath) {
- System.out
- .println(" mmUnzip mm " + pPath + " UnzipmmUnzip " + pPath);
- String mmSource = pSource;
- String mmPath = pPath;
- File fileM = new File(mmSource);
- if (!fileM.exists()) {
- System.out.println(" not exits ");
- return "";
- }
- File zipFile = new File(mmSource);
- if (!zipFile.exists()) {
- System.out.println(" not exits zipFile ");
- return "";
- }
- // zipFile.delete(); 解压后删除原zip删除
- try {
- unZipFile(zipFile, mmPath);
- } catch (ZipException e) {// 解压不成功
- zipFile.delete();
- e.printStackTrace();
- return "";
- } catch (IOException e) {
- zipFile.delete();
- e.printStackTrace();
- return "";
- }
- // zipFile.delete();
- return "ok";
- }
- public static void unZipFile(File zipFile, String folderPath)
- throws ZipException, IOException {
- File desDir = new File(folderPath);
- if (!desDir.exists()) {
- desDir.mkdirs();
- }
- ZipFile zf = new ZipFile(zipFile);
- for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();) {//枚举里面有几个文件
- ZipEntry entry = ((ZipEntry) entries.nextElement());
- // 后面插入判断是否为文件夹,如果是不处理
- String name = entry.getName();
- if (name.endsWith(File.separator))
- continue;
- InputStream in = zf.getInputStream(entry);
- String str = folderPath + File.separator + entry.getName();
- str = new String(str.getBytes("8859_1"), "GB2312");
- File desFile = new File(str);
- if (!desFile.exists()) {
- File fileParentDir = desFile.getParentFile();
- if (!fileParentDir.exists()) {
- fileParentDir.mkdirs();
- }
- desFile.createNewFile();
- }
- OutputStream out = new FileOutputStream(desFile);
- byte buffer[] = new byte[1024];
- int realLength;
- while ((realLength = in.read(buffer)) > 0) {
- out.write(buffer, 0, realLength);
- }
- in.close();
- out.close();
- }
- }