Solved

Tar through java

Posted on 2004-08-18
12
187 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
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 41 total points
ID: 11828980
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now