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();

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

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

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

And to test it…

	public static void main(String[] args)
		String url = "";
		String html = downloadHTML(url);

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.

Related Posts

Tagged with:  

Leave a Reply