This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes How to create tar using Java in windows os Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to create tar using Java in windows os" Watch "How to create tar using Java in windows os" New topic

How to create tar using Java in windows os

satya sahu
Ranch Hand

Joined: Mar 26, 2003
Posts: 97
HI all,
I have to take some backup of some files from my application using java program. The final output should be in .tar format because this backed up data will be used in the application running in linux box and the linux box due to limited space does not have any other utilities like GZIP or unzip. Only the tar is supported. Hence i need to produce the back up data in tar format.
Please advice me how to do it in windows environment ?
Sample code will be really great help for me.

Thanks in advance.
Joe Ess

Joined: Oct 29, 2001
Posts: 9191

I use cygwin to run *nix programs under Windows.

[How To Ask Questions On JavaRanch]
Sev Zaslavsky

Joined: Nov 19, 2008
Posts: 7
Seems like there are at least 3 approaches:

1. Call "tar" using one of the flavors of java.lang.Runtime.exec() . Note that this might not be portable. Joe Ess alluded how to get a "tar" that runs on windows
2. Find a tar library written in java and code against it. Here is something I found on Google search that alludes to such a library
3. Instear of tar, use jar for which java has built-in support. zip/unzip utilities are tiny in size in relation to the archives that you'll be making. This might be the path of least effort.

Which do you like best?
[ November 26, 2008: Message edited by: Sev Zaslavsky ]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Another Java tar library is Apache Commons Compress. It's currently available as source code only, but it works well.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Or you can use the GZIPOutputStream class.

Regards, Rene Larsen
Dropbox Invite
I agree. Here's the link:
subject: How to create tar using Java in windows os
It's not a secret anymore!