在java中解压缩jar的最简单方法 [英] Easiest way to unpack a jar in java

查看:137
本文介绍了在java中解压缩jar的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有一个jar文件,我想从junit测试解压缩到特定的文件夹。

Basically, I have a jar file that i want to unzip to a specific folder from a junit test.

最简单的方法是什么?
如果有必要,我愿意使用免费的第三方库。

What is the easiest way to do this? I am willing to use a free third party library if it's necessary.

推荐答案

你可以使用 java.util.jar.JarFile 迭代文件中的条目,通过其 InputStream 提取每个条目并将数据写入外部文件。 Apache Commons IO提供了一些实用工具,使其不那么笨拙。

You could use java.util.jar.JarFile to iterate over the entries in the file, extracting each one via its InputStream and writing the data out to an external File. Apache Commons IO provides utilities to make this a bit less clumsy.

这篇关于在java中解压缩jar的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆