Read HTML from URL using Java - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

Read HTML from URL using Java

Share This

package interesting; import java.net.*; import java.io.*; public class URLReader { public static void main(String[] args) throws Exception { URL url = new URL("http://itmagix.blogspot.in/"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); } in.close(); } }


package interesting; import java.net.URL; public class ParseURL { public static void main(String[] args) throws Exception { URL aURL = new URL("http://itmagix.blogspot.in/"); System.out.println("protocol = " + aURL.getProtocol()); System.out.println("userinfo = "+aURL.getUserInfo()); System.out.println("authority = " + aURL.getAuthority()); System.out.println("host = " + aURL.getHost()); System.out.println("port = " + aURL.getPort()); System.out.println("path = " + aURL.getPath()); System.out.println("query = " + aURL.getQuery()); System.out.println("filename = " + aURL.getFile()); System.out.println("ref = " + aURL.getRef()); System.out.println("content = "+aURL.getContent()); } }








Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.