How to extract tgz file using java -
is there java code extracts 'tgz' file. searched lot didn't any. first converted tar file , used code extract tar file. tar file contains xml, sh , tgz files getting stucked. code is:
public class test1 { public static void main(string[] args) throws exception{ file file = new file("d:\\delta\\interactive\\qml_windows\\development\\onemedia\\"); final list<file> untaredfiles = new linkedlist<file>(); final inputstream = new fileinputstream("d:\\onemedia\\onemedia-dal-504-v4.tar"); final tararchiveinputstream debinputstream = (tararchiveinputstream) new archivestreamfactory().createarchiveinputstream("tar", is); tararchiveentry entry = null; while ((entry = (tararchiveentry)debinputstream.getnextentry()) != null) { final file outputfile = new file(file, entry.getname()); if (entry.isdirectory()) { if (!outputfile.exists()) { if (!outputfile.mkdirs()) { throw new illegalstateexception(string.format("couldn't create directory %s.", outputfile.getabsolutepath())); } } } else { final outputstream outputfilestream = new fileoutputstream(outputfile); ioutils.copy(debinputstream, outputfilestream); outputfilestream.close(); } untaredfiles.add(outputfile); } debinputstream.close(); } } this code extracts tar file. still getting error as:
exception in thread "main" java.io.filenotfoundexception: d:\onemedia\onemedia_4\adload.tgz (the system cannot find path specified)
Comments
Post a Comment