Salu2! y gracias de antemano

Código: Seleccionar todo
import java.net.*;
import java.io.*;
public class MainClass {
public static void main(String args[]) {
URL u;
URLConnection uc;
String header;
String nextLine;
URLConnection urlConn = null;
InputStreamReader inStream = null;
BufferedReader buff = null;
try {
u = new URL("http://java.sun.com/jdc");
URLConnection connection = u.openConnection();
connection.connect();
// Cast to a HttpURLConnection
if ( connection instanceof HttpURLConnection)
{
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int code = httpConnection.getResponseCode();
System.out.println(code);
// do something with code .....
}
else
{
System.err.println ("error - not a http request!");
}
uc = u.openConnection();
for (int j = 1;; j++) {
header = uc.getHeaderField(j);
if (header == null)
break;
System.out.println(uc.getHeaderFieldKey(j) + " " + header);
}
// Create the URL obect that points
// at the default file index.html
urlConn = u.openConnection();
inStream = new InputStreamReader(
urlConn.getInputStream());
buff= new BufferedReader(inStream);
// Read and print the lines from index.html
while (true){
nextLine =buff.readLine();
if (nextLine !=null){
System.out.println(nextLine);
}
else{
break;
}
}
} catch (MalformedURLException e) {
System.err.println("not a URL I understand.");
} catch (IOException e) {
System.err.println(e);
}
}
}