Here you can find the source of getFileContentAsList(String filePath)
public static List<String> getFileContentAsList(String filePath) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; import java.util.Arrays; import java.util.List; public class Main { private final static String DEFAULT_CHARSET = "UTF-8"; public static List<String> getFileContentAsList(String filePath) throws IOException { return Arrays.asList(getFileContent(filePath).split("\\n")); }// w w w .j a v a 2 s .co m public static List<String> getFileContentAsList(File file) throws IOException { return getFileContentAsList(file, DEFAULT_CHARSET); } public static List<String> getFileContentAsList(String filePath, String encoding) throws IOException { return Arrays.asList(getFileContent(filePath, encoding) .split("\\n")); } public static List<String> getFileContentAsList(File file, String encoding) throws IOException { return Arrays.asList(getFileContent(new FileInputStream(file), encoding).split("\\n")); } public static String getFileContent(String filePath) throws IOException { return getFileContent(filePath, DEFAULT_CHARSET); } public static String getFileContent(String filePath, String encoding) throws IOException { BufferedReader buff = new BufferedReader(new InputStreamReader( new FileInputStream(filePath), encoding)); String content = getContent(buff); buff.close(); return content; } public static String getFileContent(File file) throws IOException { return getFileContent(new FileInputStream(file)); } public static String getFileContent(InputStream is) throws IOException { BufferedReader buff = new BufferedReader(new InputStreamReader(is, "UTF-8")); String content = getContent(buff); buff.close(); return content; } public static String getFileContent(InputStream is, String encoding) throws IOException { BufferedReader buff = new BufferedReader(new InputStreamReader(is, encoding)); String content = getContent(buff); buff.close(); return content; } private static String getContent(BufferedReader buff) throws IOException { String line; StringBuffer content = new StringBuffer(); while ((line = buff.readLine()) != null) { content.append('\n'); content.append(line); } return content.substring(1).toString(); } }