Mega Code Archive

 
Categories / Java / Network Protocol
 

Read from a URL

import java.net.*; import java.io.*; public class lycos {   public static void main (String[] args) {        try {       String thisLine;       URL u = new URL("http://www.google.com");       DataInputStream theHTML = new DataInputStream(u.openStream());       while ((thisLine = theHTML.readLine()) != null) {         System.out.println(thisLine);       } // while loop ends here     }     catch (MalformedURLException e) {       System.err.println(e);     }     catch (IOException e) {       System.err.println(e);     }        } }