java解压缩文件
来源:互联网 发布:淘宝背景音乐代码生成 编辑:程序博客网 时间:2024/04/27 15:33
压缩:
// 压缩 public static void zip(String zipFileName, String inputFile) throws Exception { File f = new File(inputFile); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName)); zip(out, f, null); System.out.println("zip done"); out.close(); } // 压缩 private static void zip(ZipOutputStream out, File f, String base) throws Exception { if (f.isDirectory()) { File[] fc = f.listFiles(); if (base != null) out.putNextEntry(new ZipEntry(base + "/")); base = base == null ? "" : base + "/"; for (int i = 0; i < fc.length; i++) { if (fc[i].getName().endsWith(".vmb")) { continue; } else { zip(out, fc[i], base + fc[i].getName()); } } } else { out.putNextEntry(new ZipEntry(base)); FileInputStream in = new FileInputStream(f); int b; while ((b = in.read()) != -1) out.write(b); in.close(); } }
// 解压 public static void unZipFiles(String filePath, String directoryPath) { try { File filezip = new File(filePath); ZipFile zipFile = new ZipFile(filezip); Enumeration enu = zipFile.entries(); String result = ""; while (enu.hasMoreElements()) { ZipEntry entry = (ZipEntry)enu.nextElement(); String name = entry.getName(); // 如果解压entry是目录,直接生成目录即可,不用写入,如果是文件,要讲文件写入 String path = directoryPath + File.separator + name; result = result + path + "<br/>"; File file = new File(path); if (entry.isDirectory()) { file.mkdirs(); } else { // 建议使用如下方式创建 流,和读取字节,不然会有乱码(当然要根据具体环境来定) InputStream is = zipFile.getInputStream(entry); byte[] buf1 = new byte[1024]; int len; if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); } OutputStream out = new FileOutputStream(file); while ((len = is.read(buf1)) > 0) { String buf = new String(buf1, 0, len); out.write(buf1, 0, len); } is.close(); out.flush(); out.close(); } } } catch (Exception e) { e.printStackTrace(); } }
1 0
- java解压缩文件
- java 解压缩zip文件
- 解压缩文件java源码
- java 解压缩zip文件
- java解压缩zip文件
- JAVA 解压缩文件
- java解压缩zip文件
- java zip 解压缩文件
- java 压缩文件 解压缩文件
- java 解压缩文件
- java 文件解压缩
- Java 文件 解压缩 示例
- java 压缩解压缩文件
- JAVA解压缩文件
- java解压缩文件
- java Zip文件解压缩
- Java 中 解压缩文件
- Java解压缩-Rar文件
- openGL图片占用内存计算
- viewHolder,setTag,getTag,setId,getId的使用
- 按理来'|'说是个特殊字符,为啥split需要转义,用replace不需要转义
- MSSql Server基础学习系列———聚合函数
- count和count_if函数
- java解压缩文件
- 短信发送及其验证
- 获取屏幕截图ScreenShot
- Android 安装调试出错:Installation error: INSTALL_FAILED_MEDIA_UNAVAILABLE
- 【NCRE】——c# 给PPT判分
- android开发中WebView控件的实例与注意要点——个人主页浏览器简易实现
- SharedPreferences(数据存储)
- C#进阶系列——AOP?AOP!
- oracle的卸载