/** * Reads a string of at most length <tt>maxChars</tt> from the supplied * Reader. * * @param r * The Reader to read the string from. * @param maxChars * The maximum number of characters to read. * @return A String of length <tt>maxChars</tt>, or less if the supplied * Reader did not contain that much characters. */ public static String readString(Reader r, int maxChars) throws IOException { char[] charBuf = new char[maxChars]; int charsRead = readChars(r, charBuf); return new String(charBuf, 0, charsRead); }
public static char[] readChars(URL url) throws IOException { Reader reader = urlToReader(url); try { return readChars(reader); } finally { reader.close(); } }