Latest News

 










Example 4: Fetch and print the first 30 lines of an HTML page

Previous slide Next slide Back to first slide View graphic version


Example 4: Fetch and print the first 30 lines of an HTML page


 
My other sites

Latest News

 










Example 4: Fetch and print the first 30 lines of an HTML page

    import java.io.*;
    import java.net.URL;
    public class URLReader {
    public static void main(String args[]) {
    URL myURL;
    DataInputStream myURLContent;
    try {
    myURL = new URL("http://www.cs.nott.ac.uk");
    myURLContent = new DataInputStream(myURL.openStream());
    for (int i=0; iណ i++) {
    System.out.println(myURLContent.readLine());
    }
    }
    catch (Exception e) {
    System.out.println("Error while opening URL");
    }
    }
    }

Previous slide Next slide Back to first slide View graphic version