Solved

Tar through java

Posted on 2004-08-18
12
193 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

752 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