Here you can find the source of readFileAsList(String filename, String splitter)
public static List<String> readFileAsList(String filename, String splitter) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Main { public final static String newline = System.getProperty("line.separator"); public static List<String> readFileAsList(String filename, String splitter) throws IOException { List<String> list = new ArrayList<String>(); File file = new File(filename); FileReader freader = new FileReader(file); StringBuilder builder = new StringBuilder(); try (BufferedReader breader = new BufferedReader(freader)) { String line = breader.readLine(); while (null != line) { builder.append(line);// ww w . j ava2s. c o m builder.append(newline); line = breader.readLine(); } } String fileContent = builder.toString(); String[] segs = fileContent.split(splitter); for (String seg : segs) { list.add(seg.trim()); } return list; } }