Link to home
Start Free TrialLog in
Avatar of d2marcelo
d2marcelo

asked on

Tar file from Java

Does anybody know how to tar a file using ant tasks  org.apache.tools.ant.taskdefs.Tar..?

Thanks tons.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

the doco has lots of examples
http://ant.apache.org/manual/CoreTasks/tar.html
Avatar of d2marcelo
d2marcelo

ASKER

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)
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.

objects,
do you use the TarArchive ?  if so , do you have an example?
thanks
thanks objets, that works,
but would you happen to know how to use TarGzOutputStream? to compress it.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is great.!!   thanks again..