Solved

Tar through java

Posted on 2004-08-18
12
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

627 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