Java BufferedReader Read Line readLineToList(String pathName, String enCoding)

Here you can find the source of readLineToList(String pathName, String enCoding)

Description

read Line To List

License

Open Source License

Declaration

public static List<String> readLineToList(String pathName, String enCoding) 

Method Source Code


//package com.java2s;

import java.io.BufferedReader;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.InputStreamReader;

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

public class Main {

    public static List<String> readLineToList(String pathName, String enCoding) {
        BufferedReader br = null;
        String line = "";
        List<String> lines = new ArrayList<String>();

        br = readToBufferedReader(pathName, enCoding);
        if (null == br) {
            return null;
        }//from  w w w . j av  a  2s . c  o  m
        try {
            while ((line = br.readLine()) != null) {
                lines.add(line.trim());
            }
            br.close();
        } catch (Exception e) {
        }
        return lines;
    }

    public static BufferedReader readToBufferedReader(String pathName, String enCoding) {
        try {
            return new BufferedReader(readToInputStreamReader((pathName), enCoding));
        } catch (Exception e) {
            return null;
        }
    }

    public static InputStreamReader readToInputStreamReader(String patnName, String enCoding) {
        try {
            return new InputStreamReader(readToFileInputStream(patnName), enCoding);
        } catch (Exception e) {
            return null;
        }
    }

    public static FileInputStream readToFileInputStream(String pathName) {
        try {
            return new FileInputStream(pathName);
        } catch (FileNotFoundException e) {
            return null;
        }
    }
}

Related

  1. readLineFile(String filePath)
  2. readLineFromCommand(String command[])
  3. readLineFromConsole()
  4. readLineHard(BufferedReader in)
  5. readLineList(String fileName)