We help IT Professionals succeed at work.

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

pw05
pw05 asked
on
Medium Priority
274 Views
Last Modified: 2010-03-31
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

Comment
Watch Question

Commented:
You need to use the GZIPInputStream to read it.

________
radarsh
CERTIFIED EXPERT
Top Expert 2016

Commented:
InputStream gz = new GZipInputStream(url.openStream());

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

GZipInputStream gz = new GZipInputStream(<inputstream from url>);

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Top Expert 2016

Commented:
Typo. SHould be

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

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

________
radarsh

Author

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

Author

Commented:
oh, I think I can just wrap the BufferedReader
CERTIFIED EXPERT
Top Expert 2016

Commented:
pw05 - any reason why my answer was ignored?

Author

Commented:
CEHJ - I didn't try url.openStream - I thought it had to be urlconnection.getInputStream

sorry about that
CERTIFIED EXPERT
Top Expert 2016

Commented:
No, but never mind ;-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.