Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to untar using org.apache.tools.tar
How to untar using org.apache.tools.tar [message #4863] Tue, 22 April 2003 19:29
Eclipse UserFriend
Originally posted by: susan.b.foster.intel.com

I couldn't find any examples on the web - so here is how you can extract
<filename>.tar.gz file

import org.apache.tools.tar.*;
import java.util.zip.GZIPInputStream;
import java.io.*;

private void untarFiles(String tarFileName, File dest)
throws IOException{
//assuming the file you pass in is not a dir
dest.mkdir();
//create tar input stream from a .tar.gz file
TarInputStream tin =
new TarInputStream(
new GZIPInputStream(
new FileInputStream(
new File(tarFileName))));

//get the first entry in the archive
TarEntry tarEntry = tin.getNextEntry();
while (tarEntry != null){
//create a file with the same name as the tarEntry
File destPath = new File(
dest.toString() + File.separatorChar + tarEntry.getName());
if (tarEntry.isDirectory()){
destPath.mkdir();
}
else {
FileOutputStream fout = new FileOutputStream(destPath);
tin.copyEntryContents(fout);
fout.close();
}
tarEntry = tin.getNextEntry();
}
tin.close();
}
Previous Topic:What's happening after 2.1?
Next Topic:Can't Launch under MacOS X
Goto Forum:
  


Current Time: Sun Jun 08 23:31:45 EDT 2025

Powered by FUDForum. Page generated in 0.25845 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top