Here you can find the source of readLines(InputStream in, String encoding)
Parameter | Description |
---|---|
in | InputStream |
encoding | encoding |
Parameter | Description |
---|---|
IOException | an exception |
public static List<String> readLines(InputStream in, String encoding) throws IOException
//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; } }