This reads the url from the command prompt - and prints out the contents.
Very basic.

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

public class ViewSource{


        public static void main(String args[]){

                if (args.length >= 1){
                        System.out.println("Trying url...");
                        try{
                                URL u = new URL(args[0]);
                                System.out.println("new url created");
                                try{
                                        DataInputStream i = new 
DataInputStream(u.openStream());
                                        System.out.println("new data input stream");
                                        try{
                                                String str;
                                                while( (str = i.readLine()) != null){
                                                        System.out.println(str);
                                                }
                                        }catch(Exception e){
                                                System.out.println("Reading 
exception");
                                        }

                                }catch(IOException ioe){
                                System.out.println("IO Exception");
                                }
                        }catch(MalformedURLException mue){
                                System.out.println("Malformed URL");
                        }
                }// end of if
        }// end of main

}// end of class

Is this what u want ?
Jyoti

-----Original Message-----
From:   Ravachol Pereira [SMTP:[EMAIL PROTECTED]]
Sent:   Monday, September 06, 1999 3:31 PM
To:     [EMAIL PROTECTED]
Subject:        WebSpider, printing the contents of an URL

Hi,

I am lost in the jungle of urls, urlstreamhandlers and contenthandlerfactories.
What I am trying to do is simply to get the contents of an url (the html) and
printing it.

If anyone has done this before, please send me some sample code.

This is how far I've gotten:
===
URL url = new URL(urlname);

URLConnection conn = url.openConnection();

conn.connect();

String mime = conn.getContentType();

===

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to