Java File Read getFileContentByLine(String filePath)

Here you can find the source of getFileContentByLine(String filePath)

Description

get File Content By Line

License

Apache License

Declaration

public static List<String> getFileContentByLine(String filePath) 

Method Source Code


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

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> getFileContentByLine(String filePath) {
        File file = new File(filePath);
        if (!file.exists() || !file.isFile()) {
            return null;
        }//w  w w .j a  va 2 s .  c o  m

        List<String> content = new ArrayList<String>();
        try {
            FileInputStream fileInputStream = new FileInputStream(file);
            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
            BufferedReader reader = new BufferedReader(inputStreamReader);
            String lineContent = "";
            while ((lineContent = reader.readLine()) != null) {
                content.add(lineContent);
                if (lineContent.contains("$"))
                    System.out.println(lineContent);
            }

            fileInputStream.close();
            inputStreamReader.close();
            reader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return content;
    }
}

Related

  1. getFileContent(final File srcFile)
  2. getFileContent(final String fileName)
  3. getFileContent(final String p_filename)
  4. getFileContentAsAString(final File aFile)
  5. getFileContentAsList(String filePath)
  6. getFileContentFromClasspath(String pathToFile)
  7. getFileContentIntoStrCategoriesDictionary( String fileName)
  8. getFileContentLength(String filename)
  9. getFileContentList(String filenamePath)