Solved

Tar through java

Posted on 2004-08-18
12
192 Views
Last Modified: 2012-05-05
I need to tar a text file through java using the UNIX tar. I tried using the Java class to compress the file, but the .tar.gz file generated cannot be decompressed. Is there a way or command I can execute so that I use the unix os tar command to compress the files.

Will be grateful if you could provide samples.

Thanks and regards
0
Comment
Question by:kohonen
  • 4
  • 3
  • 2
12 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11828960
>>I tried using the Java class to compress the file

Which one?
0
 
LVL 35

Accepted Solution

by:
girionis earned 43 total points
ID: 11828962
Use the following:

Runtime.getRuntime.exec("tar -xvf mytar.tar");
0
 
LVL 35

Expert Comment

by:girionis
ID: 11828964
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 41 total points
ID: 11828980
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 41 total points
ID: 11828983
You  may be better running an Ant task:

http://ant.apache.org/manual/CoreTasks/tar.html
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11828991
I use that tar package, and it seems to work fine :-)

Use it like Zip in java (write a TarEntry to a TarArchive object)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11828997
> but the .tar.gz file generated cannot be decompressed

?!  Then, just write the tar file through a GZipOutputStream...  that doesn't work?

It should... (and it works the other way in my app)
0
 
LVL 35

Expert Comment

by:girionis
ID: 11829001
Bah... Tim I was ready to post the same link too :)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11829056
:-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
by zero exception 10 69
String array comparison 4 45
printf performancy 11 84
jmeter usage 4 31
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question