Java Reader Read getReaderContentAsString(Reader reader)

Here you can find the source of getReaderContentAsString(Reader reader)

Description

Reads the content of a Reader instance and returns it as a String.

License

Open Source License

Parameter

Parameter Description
reader a parameter

Exception

Parameter Description
IOException an exception

Return

the content of a Reader instance as a String

Declaration

public static String getReaderContentAsString(Reader reader) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.io.Reader;

public class Main {
    /**/*from  ww  w  .  j a v  a  2s  .c o  m*/
     * Reads the content of a Reader instance and returns it as a String.
     * 
     * @param reader
     * @return the content of a Reader instance as a String
     * @throws IOException
     */
    public static String getReaderContentAsString(Reader reader) throws IOException {

        int count;
        final char[] buffer = new char[2048];
        final StringBuilder out = new StringBuilder();
        while ((count = reader.read(buffer, 0, buffer.length)) >= 0) {
            out.append(buffer, 0, count);
        }

        return (out.toString());
    }
}

Related

  1. getReaderAsString(Reader source)
  2. getReaderContents(Reader reader)
  3. load(InputStream input, int bufsize)
  4. loadChars(Reader in)
  5. loadFully(String path)