Return to Snippet

Revision: 12368
at March 12, 2009 11:16 by gdvickery

Initial Code
public String readURL(String address) throws Exception
    URL url = new URL(address);
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buff = new byte[1024];
    InputStream in = conn.getInputStream();
    int read;

    while((read = != -1)
        out.write(buff, 0, read);

    return out.toString().replaceAll("[\\s]+", " ");

Initial URL

Initial Description
Connects to a web page, reads in the content and strips whitespace.

Initial Title
Read a web page with Java

Initial Tags
http, java

Initial Language