} }
package lab4.t1; import java.net.*; import java.io.*; public class Lab4T1 public static void main(String[] args) { try { // Create a URL for the desired page URL url = new URL("http://stackoverflow.com/questions/9825798/how-to-read-a-text-from-a-web-page-with-java");
// Read all the text returned by the server BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String str; while ((str = in.readLine()) != null) { str = in.readLine().toString(); System.out.println(str); // str is one line of text; readLine() strips the newline character(s) } in.close(); } catch (MalformedURLException e) { } catch (IOException e) { } }
}
package lab4.t1; import java.net.*; import java.io.*; import java.net.UnknownHostException; import java.lang.SecurityException; import java.net.InetAddress; import java.util.logging.Level; import java.util.logging.Logger; public class Lab4T1 { public static void main(String[] args) throws Exception { { URL aURL =