Here you can find the source of readLines(InputStream is)
InputStream
into a string List.
Parameter | Description |
---|---|
is | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
NullPointerException | if is is <code>null</code> |
public static List<String> readLines(InputStream is) throws IOException
//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)); } }