Here you can find the source of getReaderContents(Reader reader)
Parameter | Description |
---|---|
reader | The Reader to read. |
Parameter | Description |
---|---|
IOException | If there is an error reading the stream. |
public static String getReaderContents(Reader reader) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**//from w w w. ja va2 s .com * Reads all the characters into a String. * * @param reader The Reader to read. * @return The contents of the input stream as a String * @throws IOException If there is an error reading the stream. */ public static String getReaderContents(Reader reader) throws IOException { try { StringBuffer result = new StringBuffer(); char[] buffer = new char[2048]; int read; while ((read = reader.read(buffer)) > -1) { result.append(buffer, 0, read); } return result.toString(); } finally { closeQuietly(reader); } } public static void closeQuietly(Reader input) { closeQuietly((Closeable) input); } public static void closeQuietly(InputStream input) { closeQuietly((Closeable) input); } public static void closeQuietly(Closeable input) { try { if (input != null) { input.close(); } } catch (IOException ioe) { // ignore } } }