java - Extract files from *.gz extension -
i have extracted *.gz *.tgz , have no idea how extract final files *.tgz.
there options using custom packages that's not option me, i need use standard java packages only.
what tried using same function use *.tgz *.gz doesn't work.
java.util.zip.zipexception: not in gzip format 1.gz
here function extracting *.tgz files.
public string extractfile(string path) { try { file newfile = new file(this.getfullpathwithoutextension(path) + ".gz"); gzipinputstream gstream; fileoutputstream outstream; try (fileinputstream filestream = new fileinputstream(path)) { gstream = new gzipinputstream(filestream); outstream = new fileoutputstream(newfile); byte[] buf = new byte[1024]; int len; while ((len = gstream.read(buf)) > 0) { outstream.write(buf, 0, len); } } gstream.close(); outstream.close(); newfile.createnewfile(); return newfile.getpath(); } catch (exception e) { system.out.print(e); } return null; } tl;dr; *.tgz files extracted *.gz files, *.gz files cannot extracted.
a .tgz file wouldn't extracted .gz file - extracted .tar file. (a .gz file gzipped; .tar file uncompressed archive containing multiple files; .tgz .tar file that's been gzipped - you've "undone" gzipping.)
i don't think there's within java's standard libraries handle tar files - you'll either have revisit "i can't use not in standard library" decision or reimplement yourself. file format available if decide that.
Comments
Post a Comment