Java InputStreamReader Read readFileAsList(String path)

Here you can find the source of readFileAsList(String path)

Description

read File As List

License

Apache License

Declaration

public static List<String> readFileAsList(String path) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

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 {
    public static List<String> readFileAsList(String path) throws IOException {
        List<String> ls = new ArrayList<String>();
        InputStream in = new FileInputStream(path);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
        String line = "";
        while ((line = reader.readLine()) != null) {
            line = line.trim();// w  w w.  j  a  v  a 2s.  c o  m
            if (line == null || "".equals(line)) {
                continue;
            }
            ls.add(line);
        }
        reader.close();
        return ls;
    }

    public static List<String> readFileAsList(String path, String encode) throws IOException {
        List<String> ls = new ArrayList<String>();
        InputStream in = new FileInputStream(path);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in, encode));
        String line = "";
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            if (line == null || "".equals(line)) {
                continue;
            }
            ls.add(line);
        }
        reader.close();
        return ls;
    }
}

Related

  1. readFile(ZipInputStream zin)
  2. readFileAddLine(String filePath, Object object)
  3. readFileAll(File file, String charsetName)
  4. readFileAsArray(String path)
  5. readFileAsJson(String path)
  6. readFileByCharAsString(String path, String encode)
  7. readFileCharacters(File file, boolean fix)
  8. readFileData(File file)
  9. readFileData(String directoryLocation, String fileName)