Java BufferedReader Read Line readLine(InputStream in)

Here you can find the source of readLine(InputStream in)

Description

read Line

License

Open Source License

Declaration

public static List<String> readLine(InputStream in) 

Method Source Code


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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> readLine(InputStream in) {
        return readLine(in, "utf-8");
    }/*  w  w  w.j a v a 2  s  . co m*/

    public static List<String> readLine(InputStream in, String encoding) {
        List<String> result = new ArrayList<String>();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(in, encoding));
            String line = null;
            while ((line = reader.readLine()) != null)
                result.add(line);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return result;
    }

    public static List<String> readLine(File f, String encoding) {
        try {
            return readLine(new FileInputStream(f), encoding);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    public static List<String> readLine(File f) {
        try {
            return readLine(new FileInputStream(f));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. readLine(BufferedReader reader, StringWriter writer)
  2. readLine(File f)
  3. readLine(File f)
  4. readLine(File file)
  5. readLine(File file, int lineNumber)
  6. readLine(InputStream in)
  7. readLine(InputStream input)
  8. readLine(InputStream input)
  9. readLine(RandomAccessFile wiki)