Java BufferedReader Read All readAll(Reader reader)

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

Description

read All

License

Open Source License

Declaration

public static String readAll(Reader reader) throws IOException 

Method Source Code


//package com.java2s;
// The MIT License

import java.io.BufferedReader;

import java.io.IOException;

import java.io.Reader;

public class Main {
    public static String readAll(Reader reader) throws IOException {
        StringBuffer buffer = new StringBuffer();

        BufferedReader in = new BufferedReader(reader);
        int ch;//w  w  w.  j av  a  2 s  . c  o m
        while ((ch = in.read()) > -1) {
            buffer.append((char) ch);
        }
        in.close();

        return buffer.toString();
    }

    public static String toString(Object[] array) {
        String s = "[Array ";
        if (array != null && array.length > 0) {
            s += array[0];
            for (int i = 1; i < array.length; i++)
                s += "," + array[i];
        }
        s += "]";

        return s;
    }

    public static String toString(boolean b) {
        return b ? "true" : "false";
    }
}

Related

  1. readAll(InputStream in, String encoding)
  2. readAll(InputStream input)
  3. readAll(InputStream stream)
  4. readAll(Reader reader)
  5. readAll(Reader reader)
  6. readAll(Reader reader)
  7. readAll(String fileName)
  8. readAll(String fileName)
  9. readAll(String filePath)