Possible Duplicate:
How do I extract a tar file in Java?
I’m working on an application that needs to access files within a .tar. What is the easiest way to do this? I just started Java around a week ago with a C/C++ background so I’m not sure if I can implement complicated solutions.
Also, can you treat .tgz files as zip entries?
Thanks!
Java inclides built in function for handling bot zipped and gziped libraries.
http://docs.oracle.com/javase/6/docs/api/java/util/zip/package-summary.html.
This can be used turn your
.tgzinto a regular.tarwithout much trouble. And no you cannot treat.tgzas regular zips. They are first achived in a tar and then compressed with gzip. Even if you gunzip it, you will still need to unpack the tar archive to get any of the file out of it.Handling tar files is a bit more difficult. This previous question might help :
How do I extract a tar file in Java?
From these solutions I strongly recommend the apache commons solution :
http://commons.apache.org/vfs/filesystems.html
It will allow you to read from your tar as if it were a filesystem without doing any writes to your hard drive. You will have to know what you’re looking for before you go in to it, but i doubt that will hinder you much