Download HTML Page as String with Java

On March 29, 2013, in Java, Programming, by LuCuS

Download HTML page to string with Java.

public static String downloadHTML (String uri)
{
	StringBuffer sb = new StringBuffer();

	try
	{
		URL url = new URL(uri);
	    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

	    String line;
	    while ((line = in.readLine()) != null)
	        sb.append(line + "\n");

	    in.close();
	} catch(Exception e) { }
	
	return sb.toString();
}

And to test it…

	public static void main(String[] args)
	{
		String url = "http://www.prodigyproductionsllc.com";
		String html = downloadHTML(url);
		System.out.println(html);
	}

Thank you for your interest in my site. If you find the information provided on this site useful, please consider making a donation to help continue development!

PayPal will open in a new tab.
$2.00
$5.00
Other

Related Posts

Tagged with:  

Leave a Reply