download zip file using java?
Posted
by Mohamed
on Stack Overflow
See other posts from Stack Overflow
or by Mohamed
Published on 2010-04-16T21:29:51Z
Indexed on
2010/04/16
21:33 UTC
Read the original article
Hit count: 376
I am downloading zip file from web server using Java but somehow I am loosing about 2kb in each file. I don't know why since same code works fine with other formats, e.g, text, mp3 and extra. any help is appreciated? here is my code.
public void download_zip_file(String save_to) {
try {
URLConnection conn = this.url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("content-type", "binary/data");
InputStream in = conn.getInputStream();
FileOutputStream out = new FileOutputStream(save_to + "tmp.zip");
byte[] b = new byte[1024];
int count;
while ((count = in.read(b)) > 0) {
out.write(b, 0, count);
}
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
© Stack Overflow or respective owner