Java File Content Read getFileContent(String path)

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

Description

Gets the content of a file and returns it as list of lines.

License

Open Source License

Parameter

Parameter Description
path Path to the file

Exception

Parameter Description
IOException If an I/O-Exception occurs

Return

List of lines from the content

Declaration

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

Method Source Code


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

import java.io.BufferedReader;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**//from w w  w. j  ava 2s .c  o m
     * Gets the content of a file and returns it as list of lines.
     * 
     * @param path
     *            Path to the file
     * @return List of lines from the content
     * @throws IOException
     *             If an I/O-Exception occurs
     */
    public static List<String> getFileContent(String path) throws IOException {
        BufferedReader site = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
        List<String> content = new ArrayList<String>();

        String line = site.readLine();
        while (line != null) {
            content.add(line);
            line = site.readLine();
        }

        site.close();
        return content;
    }
}

Related

  1. getFileContent(String filePath)
  2. getFileContent(String filePath)
  3. getFileContent(String filepath)
  4. getFileContent(String fName)
  5. getFileContent(String path)
  6. getFileContent(String path)
  7. getFileContent(String path)
  8. getFileContent(String path)
  9. getFileContent(String path, String encoding)