Java File Read getFileContentList(String filenamePath)

Here you can find the source of getFileContentList(String filenamePath)

Description

Utility method to get the file content, any version of this can be adapted, this is just one way of achieving the result.

License

Apache License

Parameter

Parameter Description
filenamePath a parameter

Declaration

public static List<String> getFileContentList(String filenamePath) 

Method Source Code

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

import java.io.BufferedReader;
import java.io.DataInputStream;
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 {
    /**/*w  w w  .j  a  v  a 2  s  . c  o  m*/
     * Utility method to get the file content, any version of this can be
     * adapted, this is just one way of achieving the result.
     * 
     * @param filenamePath
     * @return
     */
    public static List<String> getFileContentList(String filenamePath) {
        InputStream is;
        List<String> lines = new ArrayList<String>();
        try {
            is = new FileInputStream(new File(filenamePath));
            DataInputStream in = new DataInputStream(is);
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(in));
            String strLine;
            while ((strLine = br.readLine()) != null) {
                lines.add(strLine);
            }
            in.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return lines;
    }
}

Related

  1. getFileContentAsList(String filePath)
  2. getFileContentByLine(String filePath)
  3. getFileContentFromClasspath(String pathToFile)
  4. getFileContentIntoStrCategoriesDictionary( String fileName)
  5. getFileContentLength(String filename)
  6. getFileContentsAsString(@Nonnull final File file)
  7. getFileContentWithoutCRNL(File f, int linesPerElement, int[] setSizes)