sdc248
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("Co okie",cook ielist.toS tring());
con.getContent();
BufferedInputStream in = new BufferedInputStream(con.ge tInputStre am());
GZIPInputStream gzin = new GZIPInputStream(in);
BufferedReader br = new BufferedReader(new InputStreamReader(gzin));
while ((line=br.readLine())!=nul l) {
System.out.println("read: " + line);
}
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("Co
con.getContent();
BufferedInputStream in = new BufferedInputStream(con.ge
GZIPInputStream gzin = new GZIPInputStream(in);
BufferedReader br = new BufferedReader(new InputStreamReader(gzin));
while ((line=br.readLine())!=nul
System.out.println("read: " + line);
}
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Looks like my code is fine. The mistery is on how the files were created, perhaps?
Anyway, thank you guys for your help.
You should get rid of that. Is this url publicly available?