Clase para leer y meter en una cadena de caracteres el contenido de una URL
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class LectorUrl {
public String lee(String arg){
String inputLine;
String inputText="";
try {
// Indicamos la URL donde nos conectamos
URL url = new URL(arg);
// Buffer con los datos recibidos
BufferedReader in = null;
try {
// Volcamos lo recibido al buffer
in = new BufferedReader(new InputStreamReader(
url.openStream()));
} catch(Throwable t){}
// Transformamos el contenido del buffer a texto
// Mientras haya cosas en el buffer las volcamos a las
// cadenas de texto
while ((inputLine = in.readLine()) != null)
{
inputText = inputText + inputLine;
}
} catch (MalformedURLException me) {
System.out.println("URL erronea");
} catch (IOException ioe) {
System.out.println("Error IO");
}
return inputText;
}
public static void main(String[] args){
LectorUrl lector = new LectorUrl();
String str ="";
str = lector.lee("http://en.juantxu.net");
System.out.println(str);
}
}