fatcodeguy
Programmer
Hi,
I have an app that reads from several URLs consecutively. The first one always reads fully, but the following ones don't (Sometimes they do). It's like the app only reads about halfway and continues to the next url.
Anyone have any suggestions? Here's my code (the links i used are internal, so i haven't included them):
Thanks!!
I have an app that reads from several URLs consecutively. The first one always reads fully, but the following ones don't (Sometimes they do). It's like the app only reads about halfway and continues to the next url.
Anyone have any suggestions? Here's my code (the links i used are internal, so i haven't included them):
Code:
import java.io.*;
import java.lang.*;
import java.util.*;
import java.net.*;
public class Application{
//main function
public static void main (String args[]){
Application.run();
}//end main
public static void run(){
String[] urls = {"","",""};
//buffered readers
int ctr=0;
InputStream is = null;
BufferedReader in = null;
for (ctr=0; ctr<urls.length;ctr++){
try
{
//vars
URL url = new URL(urls[ctr]);
is = url.openStream();
in = new BufferedReader(new InputStreamReader(is));
//CONNECT to URL
URLConnection urlConnection = url.openConnection();
//READ content
//in = urlConnection.getInputStream();
int availableSize = is.available();
char[] buf = new char[availableSize];
int readSize = in.read(buf,0,availableSize);
in.close();
is.close();
//Variables to get/store doc info
System.out.println("***URL "+(ctr+1)+"/"+urls.length+": "+urls[ctr]);
String doc = new String(buf); //whole document
System.out.println(doc);
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++");
}
catch(MalformedURLException e)
{
System.err.println(ctr+" --> "+e.getMessage());
}
catch(IOException e)
{
System.err.println(ctr+" --> "+e.getMessage());
}
finally
{
}
}
}
}//end class
Thanks!!