read from Reader - Java File Path IO

Java examples for File Path IO:BufferedReader

Description

read from Reader

Demo Code


//package com.java2s;
import java.io.BufferedReader;

import java.io.IOException;

import java.io.Reader;

public class Main {
    /**//w ww.  j  a va  2 s  .c o  m
     *
     * @param reader
     * @return
     * @throws IOException
     */
    public static String readStream(Reader reader) throws IOException {
        StringBuilder result = new StringBuilder();
        BufferedReader in = new BufferedReader(reader);
        String line;
        while ((line = in.readLine()) != null) {
            result.append(line);
            result.append('\n');
        }
        in.close();
        return result.toString();
    }
}

Related Tutorials