Here you can find the source of readURLText(URL url, StringBuffer errorText)
Parameter | Description |
---|---|
url | the url of the web age to read as plain text. |
errorText | a custom message to return if something goes wrong. |
public static StringBuffer readURLText(URL url, StringBuffer errorText)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.net.URL; public class Main { /**/*from w w w .j a v a 2 s.c om*/ * Returns the raw text (i.e. with tags as "\<...\>" strings) of a web page * * @param url the url of the web age to read as plain text. * @return a StringBuffer containing the raw html text */ public static StringBuffer readURLText(URL url) { return readURLText(url, new StringBuffer("error: can't read URL " + url.toString())); } /** * Returns the raw text (i.e. with tags as "\<...\>" strings) of a web page * * @param url the url of the web age to read as plain text. * @param errorText a custom message to return if something goes wrong. * @return a StringBuffer containing the raw html text */ public static StringBuffer readURLText(URL url, StringBuffer errorText) { StringBuffer page = new StringBuffer(""); String thisLine; try { BufferedReader source = new BufferedReader( new InputStreamReader(url.openStream())); while ((thisLine = source.readLine()) != null) { page.append(thisLine + "\n"); } return page; } catch (Exception e) { return errorText; } } }