Problem downloading file from internet
Dear all,
I am trying to setup a code to download a file from the internet,
Currently, the code is very simple... Is just creating a bufferedInputStream and making a read within a loop.
But for unknown reason, at some point, the "in.read(data,0,1024);" get stucked forever...
I have no idea how to solve this,
I don't think it is related to a server side, since I can easilly download this file using other tools like wget (or somply my browser)
thanks in advance for your help,
Loicus
Code :
URL url = new URL("http://projects.hepforge.org/frog/Download/DemoFiles/V1_10/CMS/CMS.geom.gz");
InputStream in = new BufferedInputStream(url.openStream());
byte data[] = new byte[1024];
int count = 0;
int Totalcount = 0;
while(true){
System.out.printf("Read = %d --> %d\n",count, Totalcount);
count = in.read(data,0,1024);
if(count<0)break;
Totalcount+=count;
}
System.out.printf("Download is done\n");
in.close();
Re: Problem downloading file from internet
Just a precision,
the file I am trying to download is about 3.5MB,
and the process always seems to stop after ~18KB
Re: Problem downloading file from internet
then I tried to test with the "available" method, and I am of course get "0" available bytes to be read...
But why, is my number of available not increasing with type?
Should I reactive the connection in some way?
thanks,
Re: Problem downloading file from internet
Your code works fine for me (see tail end of output below).
So whatever the problem is, maybe it's not a Java problem. Have you tried other files? Do they all stop or just this one?
Read = 1024 --> 3286436
Read = 1024 --> 3287460
Read = 1024 --> 3288484
Read = 993 --> 3289477
Download is done
Re: Problem downloading file from internet
I have this problem with any (big) files...
I am working on Windows with JRE7 and I tried to desactivate the firewall, but it doesn't change anything...
Do you have any idea of what could be the source of the issue?
Thanks in advance,
Re: Problem downloading file from internet
I just remark that I have no problem when running this code from JWS,
however when I run it with eclipse "run", I have this issue with downloading...
Any ideas?
Re: Problem downloading file from internet
Weird! I ran it with Eclipse "run" and had no problems.
You could try updating Eclipse. I have JRE7 too. Sounds like an Eclipse problem if it works elsewhere!
Re: Problem downloading file from internet
yes... it was an eclipse+JRE problem,
I had 3 different version of the JRE installed and I suspect Eclipse was confused with them...
So I had to uninstall everything (JRE, JDK, Eclipse) and reinstall everything properly to solve the problem...
Its nicely working now... but I've lost a day ;-)
Thanks,