• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

How to read a .gz file that's stored on a remote server?

Hi,

Would anyone be able to guide me with how to read a .gz file that's stored on a remote server?  I know how to read a regular file using a URLConnection etc. but I'm not sure how to read from a .gz file.

Thanks for your help

0
pw05
Asked:
pw05
  • 4
  • 3
  • 2
  • +1
2 Solutions
 
radarshCommented:
You need to use the GZIPInputStream to read it.

________
radarsh
0
 
CEHJCommented:
InputStream gz = new GZipInputStream(url.openStream());

would be the heart of it
0
 
StillUnAwareCommented:
use java.util.zip.GZipInputStream:

GZipInputStream gz = new GZipInputStream(<inputstream from url>);
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
CEHJCommented:
Typo. SHould be

InputStream gz = new GZIPInputStream (url.openStream());
0
 
radarshCommented:
Connect using the normal way only, using URLConnection but wrap the inputstream you get

using:  GZIPInputStream gis = new GZIPInputStream(urlconnection.getInputStream());

________
radarsh
0
 
pw05Author Commented:
After I get the GZIPInputStream, how would I read it line by line?

(For regular files I use BufferedReader readLine() - is there a corresponding idea of a "line" using GZIPInputStream read()?)

Thanks
0
 
pw05Author Commented:
oh, I think I can just wrap the BufferedReader
0
 
CEHJCommented:
pw05 - any reason why my answer was ignored?
0
 
pw05Author Commented:
CEHJ - I didn't try url.openStream - I thought it had to be urlconnection.getInputStream

sorry about that
0
 
CEHJCommented:
No, but never mind ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now