0

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!

Community
  • 1
  • 1
joshualan
  • 2,030
  • 8
  • 23
  • 32
  • 2
    Why don't you just run the terminal command to unzip it and then look at the files? – thatidiotguy Aug 07 '12 at 17:29
  • I'm trying to make the client do as little as possible so I do not think unzipping it is a viable option. Pity though, it'd be wicked easy then. – joshualan Aug 07 '12 at 17:44

2 Answers2

5

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 .tgz into a regular .tar without much trouble. And no you cannot treat .tgz as 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

Community
  • 1
  • 1
gbtimmon
  • 4,238
  • 1
  • 21
  • 36
4

Tar file access can be done using TarArchiveEntry in the Apache Commons library.

Reimeus
  • 158,255
  • 15
  • 216
  • 276