Java解压Jar文件

这篇博客介绍了如何在Java中使用JarFile类来解压Jar文件。通过简单的API调用,开发者可以从RandomAccessFile打开的文件中读取并解压jar内容。
摘要由CSDN通过智能技术生成

今天写点java解压jar文件的东西,以前项目中用到过,很简单。。。

java中有专门的文件类型对应jar文件,那就是JarFile,用于从任何可以使用java.io.RandomAccessFile打开的文件中读取jar文件内容,详情可参考JarFile

解压只是使用JarFile的相关api,源码如下:


public class JARDecompressionTool {
	/**
	 * 解压并删除jar文件
	 */
	public static synchronized void decompress(String fileName,String outputPath){
		
			if (!outputPath.endsWith(File.separator)) {
				outputPath += File.separator;
			}
			File dir = new File(outputPath);
			if (!dir.exists()) {
				dir.mkdirs();
			}
			JarFile jf = null;
		try{
			jf =  new JarFile(fileName);
			for (Enumeration<JarEntry> e = jf.entries(); e.hasMoreElements();) {
				JarEntry je = (JarEntry) e.nextElement();
				String outFileName = outputPath + je.getName();
				File 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值