//引入jtar-(版本号).jar
public class C {
/*
* 引入jtar-(版本号).jar 使用javatar-2.5.jar 参考
* http://zhidao.baidu.com/question/808277839243169492.html
* http://billclod.iteye.com/blog/350001
*/
public void readtar() throws IOException {
String tarFile = "D:/20120725.tar.gz";
String destFolder = "D:/20120725";
File ss = new File(tarFile);
TarInputStream tis = null;
tis = new TarInputStream(new GZIPInputStream(new BufferedInputStream(new FileInputStream(ss))));
TarEntry entry;
try {
while ((entry = tis.getNextEntry()) != null) {
int count = 0;
byte data[] = new byte[204800];
FileOutputStream fos = new FileOutputStream(new File(destFolder + "/" + entry.getName()));
BufferedOutputStream dest = new BufferedOutputStream(fos);
while ((count = tis.read(data)) != -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
}
tis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
java解压tar.gz
最新推荐文章于 2024-05-16 15:30:42 发布