BufferedInputStream in = new BufferedInputStream(url.openStream());
byte[] buff = new byte[4096];
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
while(in.read(buff,0,4096) != -1){
out.write(buff, 0, 4096);
}
System.out.println("end of loop");//this doesnt print
Trying to read file from web
Started by ClemsonCS, Feb 14 2009 05:45 PM
8 replies to this topic
#1
Posted 14 February 2009 - 05:45 PM
I have this code to download files from the internet. For some reason, it gets "stuck". I put a print in the while loop and after the while loop and on certain files, it stops printing inside the loop and never prints once the loop has terminated. Any ideas? Am I using the correct objects to handle this?
|
|
|
#2
Posted 14 February 2009 - 08:16 PM
Has the server stopped sending data AND not indicated the file is done?
#3
Posted 14 February 2009 - 09:32 PM
I don't know, sounds like a possibility. How can I handle that? its not throwing any exceptions.
#4
Posted 15 February 2009 - 07:58 AM
I'm not sure. Maybe have a timeout?
#5
Posted 15 February 2009 - 12:28 PM
ClemsonCS said:
I have this code to download files from the internet. For some reason, it gets "stuck". I put a print in the while loop and after the while loop and on certain files, it stops printing inside the loop and never prints once the loop has terminated. Any ideas? Am I using the correct objects to handle this?
BufferedInputStream in = new BufferedInputStream(url.openStream());
byte[] buff = new byte[4096];
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
while(in.read(buff,0,4096) != -1){
out.write(buff, 0, 4096);
}
System.out.println("end of loop");//this doesnt print
I would really like to know, what is url and file in your code. Or else I can't read in what might not make the printer to print out the message...
#6
Posted 15 February 2009 - 11:04 PM
I am having trouble getting this error to replicate itself today. Not sure why, haven't changed the code.
#7
Posted 15 February 2009 - 11:11 PM
ClemsonCS said:
I am having trouble getting this error to replicate itself today. Not sure why, haven't changed the code.
...
I want to know what part of this is missing...
BufferedInputStream in = new BufferedInputStream([B]url[/B].openStream());I want to know what url is ! I am sure you have the whole code and not only this one...
Also I would like to know what...
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream([B]file[/B]));file is...
So could you post the whole code?
#8
Posted 15 February 2009 - 11:38 PM
url:
www.clemson.edu/administration/budget0506.pdf
file object contains:
budget0506.pdf
www.clemson.edu/administration/budget0506.pdf
file object contains:
budget0506.pdf
#9
Posted 16 February 2009 - 12:26 AM
ClemsonCS said:
url:
www.clemson.edu/administration/budget0506.pdf
file object contains:
budget0506.pdf
www.clemson.edu/administration/budget0506.pdf
file object contains:
budget0506.pdf
This far is how I come...
import java.io.*;
import java.net.*;
public class TestMe {
public static void main(String[] arg) throws IOException {
URL url = new URL("www.clemson.edu/administration/");
URLConnection cl = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(cl.getInputStream()));
int[] buff = new int[4096];
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("budget0506.pdf"));
while(in.read(null, 0, buff.length) != -1){
out.write(0);
}
in.close();
out.close();
System.out.println("end of loop");//this doesnt print
}
}
You will have to work on this or ask someone that can reach your url... I can't !


Sign In
Create Account


Back to top









