完全实现 各种变态路径的解压缩,支持在 Web 上运行(在数字签名中遇到的问题,想到了用这种写法)
2008-07-24 10:32
337 查看
package com.aspire.reportPlatform.webagent; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; /** * * @author Jhonson Lee * 实现各种路径的解压缩, 包括 url 和 绝对路径 */ public class UnZipUtil { /** * * @param sourceFile 源文件 * @param outputFolder 输出的目标目录 */ public static void unZipResources(String sourceFile,String outputFolder){ String archivePath = sourceFile; ZipInputStream zis = null; ZipEntry entry = null; URLConnection con = null; String rdpOutputFolder = outputFolder; File configFile=new File(rdpOutputFolder); if(!configFile.exists()) { configFile.mkdir(); } try { con = (new URL(archivePath)).openConnection(); con.setUseCaches(false); con.connect(); zis = new ZipInputStream(con.getInputStream()); while ((entry = zis.getNextEntry()) != null){ if (entry.isDirectory()) { String name = entry.getName(); name = name.substring(0, name.length() - 1); File f = new File(rdpOutputFolder + File.separator + name); f.mkdir(); } else { unZipResource(zis, entry.getName(),rdpOutputFolder); } } } catch (IOException ioe) { StatusPanel.getStatusPanelInstance().setStatus((byte) 8); ioe.printStackTrace(); // LogFile.getInstance().print(0, // "WebAgentApplet.installLibraries()", // "install have IOException "); }catch(Exception e){ e.printStackTrace(); }finally { con = null; try { zis.close(); } catch (IOException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } } } /** * * @param archive * @param configResourceName * @param path */ private static void unZipResource(ZipInputStream archive, String configResourceName,String path){ BufferedOutputStream out = null; byte buffer[] = new byte[1024]; int count = 0; String configFullPathName = path + File.separator + configResourceName; try { out = new BufferedOutputStream( new FileOutputStream(configFullPathName)); while ((count = archive.read(buffer)) > 0) out.write(buffer, 0, count); out.close(); } catch (IOException e) { e.printStackTrace(); }catch(Exception e){ e.printStackTrace(); }finally{ try { out.close(); } catch (IOException e1) { // TODO 自动生成 catch 块 e1.printStackTrace(); } } } } [code]
相关文章推荐
- web项目Log4j日志输出路径配置问题 问题描述:一个web项目想在一个tomcat下运行多个实例(通过修改war包名称的实现),然后每个实例都将日志输出到tomcat的logs目录下实例名命名的文
- 利用Java实现压缩与解压缩(zip、gzip)支持中文路径
- WEB开发过程中遇到的各种问题及解决方法总结
- webpack和webpack-dev-server安装配置(遇到各种问题的解决方法)
- Android SwipeRefreshLayout结合WebView使用实现以及可能遇到的问题
- Java Web 中的各种路径问题(草稿)
- 利用Java实现压缩与解压缩(zip、gzip)支持中文路径
- 怎样解决CodeBlocks运行VS编写的OpenGL项目时遇到的各种问题的
- Android 利用Java实现压缩与解压缩(zip、gzip)支持中文路径
- java WEB 开发过程中遇到的路径问题。
- 修改Tomcat默认web程序路径遇到的问题
- Android 利用Java实现压缩与解压缩(zip、gzip)支持中文路径
- C程序访问hadoop运行时遇到的各种问题以及解决方案(环境变量不被sudo继承)
- PHP5 在调用 JAVA WebService 时遇到的各种问题及解决方法(一)
- 在Tomcat上运行Web程序时遇到的一个奇怪问题.
- 【项目中】关于webView上遇到的各种问题集锦
- Windows XP环境下Visual Studio .Net运行Web项目时遇到的问题
- 利用Java实现压缩与解压缩(zip、gzip)支持中文路径
- 不知还有人遇到这个问题没有:数据库 'xxx' 的版本为 706,无法打开。此服务器支持 661 版及更低版本。不支持降级路径。
- PHP5 在调用 JAVA WebService 时遇到的各种问题及解决方法(一)