Java Reader Read Line readLines(Reader input)

Here you can find the source of readLines(Reader input)

Description

Get the contents of a Reader as a list of Strings, one entry per line.

License

Open Source License

Parameter

Parameter Description
input the <code>Reader</code> to read from, not null

Exception

Parameter Description
NullPointerException if the input is null
IOException if an I/O error occurs

Return

the list of Strings, never null

Declaration

public static List<String> readLines(Reader input) throws IOException 

Method Source Code

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

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.io.Reader;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*from  ww  w. j ava  2 s.  c om*/
     * Get the contents of an <code>InputStream</code> as a list of Strings, one
     * entry per line, using the default character encoding of the platform.
     * <p>
     * This method buffers the input internally, so there is no need to use a
     * <code>BufferedInputStream</code>.
     * 
     * @param input
     *            the <code>InputStream</code> to read from, not null
     * @return the list of Strings, never null
     * @throws NullPointerException
     *             if the input is null
     * @throws IOException
     *             if an I/O error occurs
     * @since Commons IO 1.1
     */
    public static List<String> readLines(InputStream input) throws IOException {
        InputStreamReader reader = new InputStreamReader(input);
        return readLines(reader);
    }

    /**
     * Get the contents of a <code>Reader</code> as a list of Strings, one entry
     * per line.
     * <p>
     * This method buffers the input internally, so there is no need to use a
     * <code>BufferedReader</code>.
     * 
     * @param input
     *            the <code>Reader</code> to read from, not null
     * @return the list of Strings, never null
     * @throws NullPointerException
     *             if the input is null
     * @throws IOException
     *             if an I/O error occurs
     * @since Commons IO 1.1
     */
    public static List<String> readLines(Reader input) throws IOException {
        BufferedReader reader = new BufferedReader(input);
        List<String> list = new ArrayList<String>();
        String line = reader.readLine();
        while (line != null) {
            list.add(line);
            line = reader.readLine();
        }
        return list;
    }
}

Related

  1. readLines(Reader in, boolean trim)
  2. readLines(Reader input)
  3. readLines(Reader input)
  4. readLines(Reader input)
  5. readLines(Reader input)
  6. readLines(Reader input)
  7. readLines(Reader input)
  8. readLines(Reader input)
  9. readLines(Reader input)