I have .gz and .bzip2 files and I need this to be extracted and displayed. I looked at couple of places and it mentions to use zip4j utility. Can I use this to extract and display the files? Please let me know.
I referred the post Uncompress BZIP2 archive and tried to implement as below, but I am not sure what to pass to FileOutputStream and it is giving me an error.Also,is it possible to create a file object after its uncompressed.Please assist. Thank you for all the help again.
if (getExtension(filename).equals("bz2")) {
try {
FileInputStream fin = new FileInputStream("C:\\temp\\test.bz2");
BufferedInputStream in = new BufferedInputStream(fin);
FileOutputStream out = new FileOutputStream("archive.tar");
BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in);
int buffersize = 1024;
final byte[] buffer = new byte[buffersize];
int n = 0;
while (-1 != (n = bzIn.read(buffer))) {
out.write(buffer, 0, n);
}
out.close();
bzIn.close();
}
catch (Exception e) {
throw new Error(e.getMessage());
}
Thanks in advance.
~Akshitha