Here you can find the source of readAllToString(Reader reader)
Parameter | Description |
---|---|
reader | Reader |
Parameter | Description |
---|---|
IOException | an exception |
public static String readAllToString(Reader reader) throws IOException
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.IOException; import java.io.Reader; public class Main { /**/*from w w w. j av a 2 s .co m*/ * Reads all from a Reader into a String. Close the Reader when finished. * * @param reader Reader * @return the String * @throws IOException */ public static String readAllToString(Reader reader) throws IOException { char buf[] = new char[4096]; StringBuilder strBuffer = new StringBuilder(); int size = 0; try { while ((size = reader.read(buf)) != -1) { strBuffer.append(buf, 0, size); } } finally { reader.close(); } return strBuffer.toString(); } }