Java InputStream Read Line readLines(InputStream inputStream)

Here you can find the source of readLines(InputStream inputStream)

Description

Read a UTF-8 file into an array of lines and close the stream.

License

Academic Free License

Declaration

public static String[] readLines(InputStream inputStream) throws IOException 

Method Source Code


//package com.java2s;
// Licensed under the Academic Free License version 3.0

import java.io.*;
import java.util.*;

public class Main {
    /**/* www  . ja v  a 2 s  . com*/
     * Read a UTF-8 file into an array of lines.
     */
    public static String[] readLines(File f) throws IOException {
        return readLines(new FileInputStream(f));
    }

    /**
     * Read a UTF-8 file into an array of lines and close the stream.
     */
    public static String[] readLines(InputStream inputStream) throws IOException {
        BufferedReader in = null;
        try {
            ArrayList lines = new ArrayList();
            in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
            String line;
            while ((line = in.readLine()) != null)
                lines.add(line);
            return (String[]) lines.toArray(new String[lines.size()]);
        } finally {
            try {
                if (in != null)
                    in.close();
            } catch (Exception e) {
            }
        }
    }
}

Related

  1. readLines(InputStream input, String encoding)
  2. readLines(InputStream input, String encoding)
  3. readLines(InputStream input, String encoding)
  4. readLines(InputStream input, String encoding)
  5. readLines(InputStream inputStream)
  6. readLines(InputStream inputStream)
  7. readLines(InputStream is)
  8. readLines(InputStream is)
  9. readLines(InputStream is)