Java InputStream Read Line readLines(InputStream is)

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

Description

Load the content of InputStream into a string List.

License

Open Source License

Parameter

Parameter Description
is a parameter

Exception

Parameter Description
IOException an exception
NullPointerException if is is <code>null</code>

Declaration

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

Method Source Code

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

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 {
    /**/*from www.  j  a  v  a  2  s  . c om*/
     * Load the content of <code>InputStream</code> into a string List. The
     * input must be UTF-8 encoded. The method automatically closes the stream
     * after operation is finished.
     * 
     * @param is
     * @return
     * @throws IOException
     * @throws NullPointerException
     *             if is is <code>null</code>
     * @since 6.1
     */
    public static List<String> readLines(InputStream is) throws IOException {
        try {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(is, "UTF-8"));
            List<String> ret = new ArrayList<String>();
            while (reader.ready()) {
                ret.add(reader.readLine());
            }
            return ret;
        } finally {
            is.close();
        }
    }

    /**
     * Load the content of given {@link File} into a string List. The
     * input must be UTF-8 encoded.
     * 
     * @param file the File
     * @return
     * @throws IOException
     * @throws NullPointerException
     *             if is is <code>null</code>
     * @since 6.1
     */
    public static List<String> readLines(File file) throws IOException {
        return readLines(new FileInputStream(file));
    }
}

Related

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