public void unTarGz(File file,String outPutDir) throws Exception{
TarInputStream in=null;
OutputStream out=null;
try{
in=new TarInputStream(new GZIPInputStream(new BufferedInputStream(new FileinputStream(file))),
BUFFER_SIZE);
createDir(outPutDir,null);
TarEntry entry=null;
while((entry=in.getNextEntry()) !=null){
if(entry.isDirectory()){
createDir(outPutDir,entry.getName());
} else {
File tmpFile=new File(outPutDir+File.separator+entry.getName());
createDir(tmpFile.getParent()+File,separator,null);//创建输出目录
out=new FileOutputStream(tmpFile);
int length=0;
byte[] b=new byte[BUFFER_SIZE];
while((length=in.read(b)) !=-1){
out.write(b,0,length);
}
}
}
}catch(Exception e){
throw new Exception("文件解压出错",e);
}finally{
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
}
public void createDir(String outputDir,String subDir){
File file=new File(outputDir);
if(subDir !=null && !"".equals(subDir.trim)){
file=new File(outputDir+File.separator+subDir);
}
if(!file.exists()){
file.mkdirs();
}
}