import java.io.*; 
import java.net.*;

class EsempioURL 
{
    public static void main(String args[])
    {
        String indirizzo;

        if (args.length > 0)
        {
            indirizzo = args[0];
        }
        else
        {
            System.out.println("Uso: EsempioURL URL");
            return;
        }

        URL u = null;
        try 
        { 
            u = new URL(indirizzo);
            System.out.println("URL aperto: " + u);
        }
        catch (MalformedURLException e) 
        {
            System.out.println("URL errato: " + u);
        }

        URLConnection c = null;
        DataInputStream istream = null;

        try 
        {
            System.out.print("Connessione in corso...");
            c = u.openConnection();
            c.connect();
            System.out.println("ok.");
            BufferedInputStream b = new
            BufferedInputStream(c.getInputStream());
            istream = new DataInputStream(b);
            System.out.println("Lettura dei dati...");
            String s;
            while( (s = istream.readLine()) != null )
                System.out.println(s); 
        }
        catch (IOException e) 
        {
            System.out.println(e.getMessage());
        }
    }
}
