• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to download binary file

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to automatically download some zip file. I write this code

url = new URL("http://someaddress/file.zip");
conn = url.openConnection();
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
FileWriter fout = new FileWriter("temp.zip");
while ((character = rd.read()) != -1) {
fout.write(character);
}
rd.close();
fout.flush();
fout.close();

To my surprise I found out, that my temp.zip file is always corrupted in this way: characters 90h, 98h, 83h, 81h, 88h (and maybe others) are replaced by character 3F. When downloading via browser, file is OK. I don't have the slightest idea why this happens.

Thanks in advance for any comments.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The various Reader and Writer classes are for character data. For binary data (like ZIP files) you need to use Stream classes.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic