Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Problem downloading file from internet

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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

    				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();


  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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,

  4. #4
    Junior Member
    Join Date
    Nov 2011
    Location
    Budapest, Hungary
    Posts
    10
    My Mood
    Mellow
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default 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
    Cave of Programming -- programming info and help, exercises, tutorials and other stuff.

  5. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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,

  6. #6
    Junior Member
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?

  7. #7
    Junior Member
    Join Date
    Nov 2011
    Location
    Budapest, Hungary
    Posts
    10
    My Mood
    Mellow
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default 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!
    Cave of Programming -- programming info and help, exercises, tutorials and other stuff.

  8. #8
    Junior Member
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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,

Similar Threads

  1. JAVA help on file: Internet Service Provider
    By Plural in forum What's Wrong With My Code?
    Replies: 26
    Last Post: March 30th, 2014, 11:03 PM
  2. Downloading the file in Lotus Symphony spreadsheet format (ods)
    By chinnu in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 13th, 2011, 02:47 AM
  3. Downloading help with JDK 6
    By oneofthelions in forum Java Theory & Questions
    Replies: 1
    Last Post: December 13th, 2009, 07:36 AM
  4. Java program for downloading contents from the web
    By alley in forum Java Networking
    Replies: 8
    Last Post: June 17th, 2009, 01:13 PM
  5. Internet Filter to display some website
    By sundarjothi in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: May 15th, 2008, 05:03 AM