Java InputStream Read Line readLines(InputStream in, String encoding)

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

Description

get the content from an InputStream as a list of strings

License

Open Source License

Parameter

Parameter Description
in InputStream
encoding encoding

Exception

Parameter Description
IOException an exception

Return

a list of strings

Declaration

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

Method Source Code


//package com.java2s;
/*//from ww w . j av a  2s. com
 * Copyright 1999-2011 Alibaba.com All right reserved. This software is the confidential and proprietary information of
 * Alibaba.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with Alibaba.com.
 */

import java.io.BufferedReader;

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

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

public class Main {
    /**
     * get the content from an {@link InputStream} as a list of strings
     * 
     * @param in InputStream
     * @param encoding encoding
     * @return a list of strings
     * @throws IOException
     */
    public static List<String> readLines(InputStream in, String encoding) throws IOException {
        InputStreamReader reader = null;
        if (encoding == null) {
            reader = new InputStreamReader(in);
        } else {
            reader = new InputStreamReader(in, encoding);
        }
        BufferedReader br = new BufferedReader(reader);
        List<String> lines = new ArrayList<String>();
        String line;
        while ((line = br.readLine()) != null) {
            lines.add(line);
        }
        return lines;
    }
}

Related

  1. readLines(InputStream in)
  2. readLines(InputStream in)
  3. readLines(InputStream in)
  4. readLines(InputStream in, int maxArraySize)
  5. readLines(InputStream in, String charset)
  6. readLines(InputStream input)
  7. readLines(InputStream input)
  8. readLines(InputStream input)
  9. readLines(InputStream input)