Java InputStream Read Line readLines(InputStream stream)

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

Description

read Lines

License

Open Source License

Declaration

public static List<String> readLines(InputStream stream) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> readLines(InputStream stream, String charsetname) throws Exception {
        List<String> lines = new ArrayList<String>();
        BufferedReader reader = null;
        try {/*from   w w w  .  jav  a 2s.  c  om*/
            reader = new BufferedReader(new InputStreamReader(stream, charsetname));
            String line = null;
            while ((line = reader.readLine()) != null) {
                lines.add(line);
            }
            return lines;
        } finally {
            if (reader != null)
                reader.close();
        }
    }

    public static List<String> readLines(InputStream stream) throws Exception {
        List<String> lines = new ArrayList<String>();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(stream));
            String line = null;
            while ((line = reader.readLine()) != null) {
                lines.add(line);
            }
            return lines;
        } finally {
            if (reader != null)
                reader.close();
        }
    }
}

Related

  1. readLines(InputStream is)
  2. readLines(InputStream is2, String encoding)
  3. readLines(InputStream is2, String encoding)
  4. readLines(InputStream stream)
  5. readLines(InputStream stream)
  6. readLines(InputStream stream, String charset)
  7. readLinesCommon(InputStream in)
  8. readLineSet(InputStream stream)
  9. readLinesStream(InputStream is, boolean trim)