获取zip包中的jar。然后将zip包中的jar拷贝在指定目录。个人demo
来源:互联网 发布:修改网卡mac的软件 编辑:程序博客网 时间:2024/06/05 17:13
@Overrideprotected boolean unpackSoFile(File objFile, String directory) {try{List<String> list=new ArrayList<String>();//解压zipZipFile zipFile = new ZipFile(objFile,Charset.forName("GBK"));copyFileToDirectory(zipFile,directory);Enumeration<?> entries = zipFile.entries(); while(entries.hasMoreElements()){ZipEntry zipEntry=(ZipEntry)entries.nextElement();String entryName=zipEntry.getName();if(entryName.endsWith(".jar")){JarFile jarFile = new JarFile((directory +File.separator+ entryName).replaceAll("\\*", "/"));Enumeration<?> fileList = jarFile.entries();while (fileList .hasMoreElements()) {JarEntry jarEntry = (JarEntry)fileList.nextElement();String jarEntryName=jarEntry.getName().replaceAll("/", ".");if(jarEntryName.endsWith(".class")&&Class.forName(jarEntryName.substring(0, jarEntryName.length()-6)).newInstance() instanceof LifeCycle){ list.add(jarEntryName.substring(0, jarEntryName.length()-6));}}jarFile.close();}}}catch(Exception e){log.info("上传到指定目录异常:{}",e);return false;}return true;}
private void copyFileToDirectory(ZipFile zipFile, String directory){InputStream in=null;FileOutputStream out=null;try { for (Enumeration<? extends ZipEntry> entries = zipFile.entries(); entries.hasMoreElements();) { ZipEntry entry = (ZipEntry) entries.nextElement(); String zipEntryName = entry.getName(); in = zipFile.getInputStream(entry); out = new FileOutputStream(directory + File.separator +zipEntryName); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } log.info("******************拷贝完毕********************"); } catch (IOException e) {log.info("解压到指定目录异常,{}",e);}finally{try{in.close(); out.close();}catch(Exception e){log.info("关闭流异常:{}",e);}}}
ZipsoRegisty zz= new ZipsoRegisty();zz.unpackSoFile(new File("E:/113-v1.0.1.zip"), "F:/");
阅读全文
0 0
- 获取zip包中的jar。然后将zip包中的jar拷贝在指定目录。个人demo
- maven解压zip包将jar包copy到指定目录
- 获取jar包中的目录及文件
- jar命令解压zip包
- ant.jar打ZIP包
- 将Jar包中的文件拷贝到本地文件
- 将sqlserver中的图片打成zip包
- jar包 zip和 tgz区别
- 指定执行jar包中的某个main
- spring中的jar包
- java中的jar包
- cdt的zip包中的features和plugins目录展
- jar包中的资源获取<转>
- 获取本地jar包中的图片
- 获取 Android Studio 中的jar包
- 获取jar包中的文件路径
- 获取jar包中的class类
- java实现文件夹下解压jar包和zip包
- Warning:The `android.dexOptions.incremental` property is deprecated and it has no effect on the buil
- JSP概述
- pb_ds平衡树-模板
- php写入文件fwrite和file_put_contents函数比较
- 防止网页被嵌入框架的代码
- 获取zip包中的jar。然后将zip包中的jar拷贝在指定目录。个人demo
- centos上安装mysql并设置远程访问
- PHP远程访问文件
- php实现单文件上传
- 设计模式最简Demo:工厂方法模式[Factory Method Pattern]
- C++中endl和"\n"的区别
- JAVA学习(2)
- PHP文件指针操作
- C语言一些理解