Here you can find the source of readLines(final Reader input)
Parameter | Description |
---|---|
input | the Reader to read from, not null |
Parameter | Description |
---|---|
IOException | if an I/O error occurs |
public static ArrayList<String> readLines(final Reader input) throws IOException
//package com.java2s; /*/* w ww. j a v a 2s .c o m*/ * Copyright (c) 2014 Haixing Hu * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; import java.util.ArrayList; public class Main { /** * Get the contents of a {@code Reader} as a list of Strings, one entry * per line. * * This method buffers the input internally, so there is no need to use a * {@code BufferedReader}. * * Note that the caller MUST close the reader by itself. * * @param input * the {@code Reader} to read from, not null * @return the array list of Strings. It never be null, but could be empty. * @throws IOException * if an I/O error occurs */ public static ArrayList<String> readLines(final Reader input) throws IOException { final BufferedReader reader = new BufferedReader(input); final ArrayList<String> result = new ArrayList<String>(); String line = reader.readLine(); while (line != null) { result.add(line); line = reader.readLine(); } return result; } }