java - BZip2 - What to be passed to FileOutputstream for different types of files -
i trying extract bz2 file mentioned below, test class wrote , know .txt file when uncompressed, when read server, uncompressed bz2 file can html, tar,tgz or text files, how able make code generic such work kind of file.
i want uncompress different files, if test.txt.bz2, uncompress test.txt , 6223.webvis.html_20130803195241.bz2 6223.webvis.html_20130803195241. how can make code generic such work these 2 different scenarios.
try{ fileinputstream fin = new fileinputstream("c:\\temp\\test.txt.bz2"); bufferedinputstream in = new bufferedinputstream(fin); fileoutputstream out = new fileoutputstream("c:\\temp\\test.txt"); 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, akshitha.
a bz2 archive not know original name. usual way compress file.ext
file.ext.bz2
, output file name archive name.
string infile = "test.bz2"; string outfile = infile.substring(0, infile.length() - 4); // outfile == "test"
Comments
Post a Comment