| Author |
opening .gz file and extracting the .txt file
|
Jacob Sonia
Ranch Hand
Joined: Jun 28, 2009
Posts: 164
|
|
Hi,
I have a .gz file and when i try extracting it, it has a .txt file and i want to open the .gz file and extract this .txt file and place it in another folder. Please advise how i can achieve this. I tried a few open source programs but didn't really work.
Thanks,
|
 |
Greg Charles
Bartender
Joined: Oct 01, 2001
Posts: 2535
|
|
|
Unlike a .zip file, a .gz is just a single compressed file, though often that file is a tar archive. Let's assume your file is just a simple compressed text file. You don't even have to search around for an open source solution, because standard Java already includes a GZIPInputStream class. You can wrap your FileInputStream in that, and then wrap the result in a BufferedReader or whatever gives you the interface you want. Read the contents of the file and write it out in plain text where you want it to go.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
You forgot InputStreamReader; BufferedReader takes a Reader, not an InputStream. So the entire chain is this:
Jacob, don't be intimidated by the nesting; you can use temporary variables if you want:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: opening .gz file and extracting the .txt file
|
|
|