java 文件解压(zip或rar)源代码

本文提供了一个使用Java进行文件解压的示例代码。通过修改路径和文件名,可以轻松实现不同文件的解压操作。该代码展示了如何读取ZIP文件中的条目并将其解压到指定目录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分享文件解压的源码作为参考:

修改文件路径即可使用下面代码,

 

public static void zipGetIcon() throws IOException{

		// TODO Auto-generated method stub
		ZipInputStream zis = new ZipInputStream(new FileInputStream("D:\\a.zip"));
		ZipEntry entry = null;
		ZipFile file = new ZipFile("D:\\a.zip");
		int ch = -1;
		byte[] buf = new byte[8 * 1024];
		while((entry = zis.getNextEntry()) != null){
			System.out.println(entry);
			File outFile = new File("D:\\kingfo_zhou\\" + entry.getName() + ".jpg");
			if(!outFile.getParentFile().exists()){
				outFile.getParentFile().mkdirs();
			}
			if(!outFile.exists()){
				outFile.createNewFile();
			}
			FileOutputStream out = new FileOutputStream(outFile);
			InputStream is = file.getInputStream(entry);
			while((ch = is.read(buf)) != -1){
				out.write(buf, 0, ch);
				out.flush();
			}
			out.close();
		}
		zis.close();
		file.close();
		System.out.println();
	}

可以修改这个方法,路径对外开发等,或者命名规则按照用户自定义也可以。

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值