/* URL class example * This example illustrates how we can use the URL class to read * the source html code of a web page. The html code of the page is * displayed on the standard output device. The provided address must * follow the format "http:// .....". * */ package url; import java.io.*; import java.net.*; import javax.swing.*; public class ReadingWebPageHtml { public static void main(String[] args) { String webSite = JOptionPane.showInputDialog("Enter web address (http:// required)"); try { URL url = new URL(webSite); /* Obtaining a stream object to read the html code */ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(url.openStream())); String inputLine; while ((inputLine = bufferedReader.readLine()) != null) { System.out.println(inputLine); } bufferedReader.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }