Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Tar through java

Posted on 2004-08-18
12
Medium Priority
?
205 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 172 total points
ID: 11828962
Use the following:

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

Expert Comment

by:girionis
ID: 11828964
0
Technology Partners: 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 164 total points
ID: 11828980
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 164 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

972 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