Win a copy of Java Challengers this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

write binary file doesn't work in some PC

 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using Eclipse with compiler 1.5 to build a program, which is to download some jar files from an URL. It's working in my own PC, with JRE 1.6.0_01. But it's not working in another PC, with JRE 1.5.0_11. On the PC with JRE 1.5, it only downloaded/created empty jar files.

Here is the code for downloading:



For the PC that is JRE 1.5, the code while (ins.available() != 0) did not get executed at all.
Is there anything wrong with this code?

Thanks.
 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AvailableDoesntDoWhatYouThinkItDoes
 
author
Posts: 23899
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I think you have a misunderstanding of the available() method. The available() method returns the number of bytes which can be read without blocking -- it doesn't return the number of bytes til the end of file. So, your loop will copy only what is buffered -- which can be different from system to system, depending on how much read-ahead the OS does.

[EDIT: Wow. I didn't know that there was a FAQ for this... ]

Henry
 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. Now its working....
 
A wop bop a lu bop a womp bam boom! Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic