Link to home
Start Free TrialLog in
Avatar of sdc248
sdc248Flag for United States of America

asked on

read .gz file in java

Hi:

I need to download a .gz file online. Inside the gzip file is one csv file. All is well except that I am only getting first line (the table head) of the file.  Here's the code, please help:

String url  = new URL ("myurl");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("GET");
con.setRequestProperty("Cookie",cookielist.toString());
con.getContent();
                                    
BufferedInputStream in = new BufferedInputStream(con.getInputStream());
GZIPInputStream gzin = new GZIPInputStream(in);
BufferedReader br = new BufferedReader(new InputStreamReader(gzin));
while ((line=br.readLine())!=null) {
     System.out.println("read: " + line);
}
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>con.getContent();

You should get rid of that. Is this url publicly available?
Avatar of sdc248

ASKER

With or without that line doesn't seem to make a difference.

The url is a password protected https web page. My code manages to login and read the html content of the web page where the file is published.
Make sure you're not ignoring any exceptions.
ASKER CERTIFIED SOLUTION
Avatar of Hegemon
Hegemon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sdc248

ASKER

I tried to have my code to download and read another .gz file on the same web page and it worked!

Looks like my code is fine. The mistery is on how the files were created, perhaps?

Anyway, thank you guys for your help.