• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

opening .gz file and extracting the .txt file

 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic