How to read content of an web page using Java? - BunksAllowed

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

Community

How to read content of an web page using Java?

Share This
WebPageReader.java
import java.net.*; import java.io.*; public class WebPageReader { public static void main(String[] args) { if (args.length > 0) { try { URL u = new URL(args[0]); URLConnection uc = u.openConnection(); InputStream raw = uc.getInputStream(); InputStream buffer = new BufferedInputStream(raw); Reader r = new InputStreamReader(buffer); int c; while ((c = r.read()) != -1) { System.out.print((char) c); } } catch (MalformedURLException e) { System.err.println(args[0] + " is not a parseable URL"); } catch (IOException e) { System.err.println(e); } } } }

Happy Exploring!

No comments:

Post a Comment

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