您的位置:首页 > 编程语言 > Java开发

使用javatar解压tar包等

2015-09-25 10:46 483 查看
1、下载javatar-2.5.jar

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

2、使用方法:

/**
* 解压tar包
*
* @author: kpchen@iflyte.com
* @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/");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: