Here you can find the source of readAllLines(InputStream stream, Charset charset)
Parameter | Description |
---|---|
stream | the stream to read from |
charset | the charset to use for reading from the stream |
Parameter | Description |
---|---|
IOException | if an error during reading occurs |
public static List<String> readAllLines(InputStream stream, Charset charset) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; public class Main { private static final Charset UTF8 = Charset.forName("UTF-8"); /**/*from w w w.java2 s. c o m*/ * Reads all lines via {@link #readAllLines(InputStream, Charset)} with UTF-8 as the charset. * * @param stream the stream to read from * @return the read lines * @throws IOException if an error during reading occurs */ public static List<String> readAllLines(InputStream stream) throws IOException { return readAllLines(stream, UTF8); } /** * Reads all lines using a {@link BufferedReader} and the given charset. * * @param stream the stream to read from * @param charset the charset to use for reading from the stream * @return the read lines * @throws IOException if an error during reading occurs */ public static List<String> readAllLines(InputStream stream, Charset charset) throws IOException { if (stream == null) { return Collections.emptyList(); } try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset))) { return reader.lines().collect(Collectors.toList()); } catch (IOException e) { throw new IOException("An error occurred during reading lines.", e); } } }