Here you can find the source of getFileContent(String path)
Parameter | Description |
---|---|
path | Path to the file |
Parameter | Description |
---|---|
IOException | If an I/O-Exception occurs |
public static List<String> getFileContent(String path) throws IOException
//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; } }