With Java 7 and the Scanner trick, you can do the following:
public static String toHtmlString(URL url) throws IOException { Objects.requireNonNull(url, "The url cannot be null."); try (InputStream is = url.openStream(); Scanner sc = new Scanner(is)) { sc.useDelimiter("\\A"); if (sc.hasNext()) { return sc.next(); } else { return null;
Paul vargas
source share