Here you can find the source of readlines(final InputStream stream)
Parameter | Description |
---|---|
stream | the file to read from |
Parameter | Description |
---|---|
IOException | an exception |
public static String[] readlines(final InputStream stream) throws IOException
//package com.java2s; 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 { /**// ww w. ja v a 2 s . c o m * @param file the file to read from * @return the lines in the file * @throws IOException */ public static String[] readlines(final File file) throws IOException { final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); String line = null; final List<String> allLines = new ArrayList<String>(); while ((line = br.readLine()) != null) { allLines.add(line); } br.close(); return allLines.toArray(new String[allLines.size()]); } /** * @param file the file to read from * @param encoding * @return the lines in the file * @throws IOException */ public static String[] readlines(final File file, String encoding) throws IOException { final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding)); String line = null; final List<String> allLines = new ArrayList<String>(); while ((line = br.readLine()) != null) { allLines.add(line); } br.close(); return allLines.toArray(new String[allLines.size()]); } /** * @param stream the file to read from * @return the lines in the file * @throws IOException */ public static String[] readlines(final InputStream stream) throws IOException { final BufferedReader br = new BufferedReader(new InputStreamReader(stream)); String line = null; final List<String> allLines = new ArrayList<String>(); while ((line = br.readLine()) != null) { allLines.add(line); } return allLines.toArray(new String[allLines.size()]); } /** * @param stream the file to read from * @param encoding the inputstream encoding * @return the lines in the file * @throws IOException */ public static String[] readlines(final InputStream stream, String encoding) throws IOException { final BufferedReader br = new BufferedReader(new InputStreamReader(stream, encoding)); String line = null; final List<String> allLines = new ArrayList<String>(); while ((line = br.readLine()) != null) { allLines.add(line); } return allLines.toArray(new String[allLines.size()]); } }