Java InputStream Read Line readLines(InputStream in)

Here you can find the source of readLines(InputStream in)

Description

read Lines

License

Open Source License

Declaration

public static List<String> readLines(InputStream in) throws IOException 

Method Source Code

//package com.java2s;
/*//from   ww w  .j a  v a2 s  . c o  m
 * (C) Copyright 2006-2010 Nuxeo SAS (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     bstefanescu
 */

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;

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

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

public class Main {
    public static List<String> readLines(File file) throws IOException {
        InputStream in = new FileInputStream(file);
        return readLines(in);
    }

    public static List<String> readLines(InputStream in) throws IOException {
        List<String> lines = new ArrayList<String>();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(in));
            String line;
            while ((line = reader.readLine()) != null) {
                lines.add(line);
            }
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                }
            }
        }
        return lines;
    }
}

Related

  1. readLines(final InputStream input, final String encoding)
  2. readLines(final InputStream inputStream)
  3. readLines(final InputStream inputStream)
  4. readLines(final InputStream is)
  5. readlines(final InputStream stream)
  6. readLines(InputStream in)
  7. readLines(InputStream in)
  8. readLines(InputStream in)
  9. readLines(InputStream in)