使用javatar解压tar包等

本文将指导您如何下载并使用javatar-2.5.jar,包括解压tar包的方法及测试代码示例。

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

1、下载javatar-2.5.jar

资源:http://pan.baidu.com/s/1pJOQ6wz

 

2、使用方法:

 

/**
	 * 解压tar包
	 * 
	 * @author: 
	 * @createTime: 2015年9月23日 下午5:41:56
	 * @history:
	 * @param filename
	 *            tar文件
	 * @param directory
	 *            解压目录
	 * @return
	 */
	private static boolean extTarFileList(String filename, String directory) {
		boolean flag = false;
		OutputStream out = null;
		try {
			TarInputStream in = new TarInputStream(new FileInputStream(new File(filename)));
			TarEntry entry = null;
			while ((entry = in.getNextEntry()) != null) {
				if (entry.isDirectory()) {
					continue;
				}
				System.out.println(entry.getName());
				File outfile = new File(directory + entry.getName());
				new File(outfile.getParent()).mkdirs();
				out = new BufferedOutputStream(new FileOutputStream(outfile));
				int x = 0;
				while ((x = in.read()) != -1) {
					out.write(x);
				}
				out.close();
			}
			in.close();
			flag = true;
		} catch (IOException ioe) {
			ioe.printStackTrace();
			flag = false;
		}
		return flag;
	}


3、测试

 

 

extTarFileList("D:/Test/ibs/20150925.tar", "D:/Test/ibs/temp/");

 

 

 

 

 

 

 

 

 

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时间辜负了谁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值