Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

problems downloading a URL to a File

  Asked By: Darcy    Date: Jan 11    Category: Java    Views: 561

I made the method shown below that works when I debug, but don't when
I run...

public void downloadFile(File localFile, URL urlTarget) throws
InputStream is = urlTarget.openConnection().getInputStream();
FileOutputStream os = new FileOutputStream(localFile);
int i=0;
int offset= 0;
byte[] b = new byte[is.available()];
offset += is.read(b,offset,is.available());
I think that when I run the method the connection did not have
enougth time to make any data avaliable making is.available() == 0
even when there is a entire file to come...
how can I work around this?



No Answers Found. Be the First, To Post Answer.

Didn't find what you were looking for? Find more on problems downloading a URL to a File Or get search suggestion and latest updates.