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
Solved

Tar file from Java

Posted on 2009-07-12
8
333 Views
Last Modified: 2012-05-07
Does anybody know how to tar a file using ant tasks  org.apache.tools.ant.taskdefs.Tar..?

Thanks tons.
0
Comment
Question by:d2marcelo
  • 4
  • 4
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24836831
the doco has lots of examples
http://ant.apache.org/manual/CoreTasks/tar.html
0
 

Author Comment

by:d2marcelo
ID: 24836849
thanks objects,

here is my code

       Tar t = new Tar();
      t.setBasedir(new File("c:\\test"));
      t.setDestFile(new File("c:\\test.tar"));
      t.execute();

I get

       Exception in thread "main" java.lang.NullPointerException
      at org.apache.tools.ant.types.AbstractFileSet.setupDirectoryScanner(AbstractFileSet.java:382)
      at org.apache.tools.ant.types.AbstractFileSet.getDirectoryScanner(AbstractFileSet.java:356)
      at org.apache.tools.ant.taskdefs.Tar$TarFileSet.getFiles(Tar.java:473)
      at org.apache.tools.ant.taskdefs.Tar.execute(Tar.java:231)
0
 
LVL 92

Expert Comment

by:objects
ID: 24836851
I've always used trustice package http://www.trustice.com/java/tar/
you'll probably need to give it some context to use it outside ant, will check and get back top you.

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:d2marcelo
ID: 24836885
objects,
do you use the TarArchive ?  if so , do you have an example?
thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 24837255
0
 

Author Comment

by:d2marcelo
ID: 24837613
thanks objets, that works,
but would you happen to know how to use TarGzOutputStream? to compress it.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 24837639
theres an example here http://www.coderanch.com/t/292263/JSP/java/Downloading-TarGz-file
or use a GZIPOutputStream for the output stream passed to TarArchive constructor
0
 

Author Closing Comment

by:d2marcelo
ID: 31602684
This is great.!!   thanks again..
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

809 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