aspose file tools
The moose likes Java in General and the fly likes opening .gz file and extracting the .txt file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "opening .gz file and extracting the .txt file" Watch "opening .gz file and extracting the .txt file" New topic
Author

opening .gz file and extracting the .txt file

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 179
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
Sheriff

Joined: Oct 01, 2001
Posts: 2898
    
  12

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: 20044
    
  30

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 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
wood burning stoves
 
subject: opening .gz file and extracting the .txt file
 
It's not a secret anymore!