Here you can find the source of readFileToList(String fileName, List
public static void readFileToList(String fileName, List<String> list)
//package com.java2s; //License from project: Open Source License import java.io.Closeable; import java.io.File; import java.io.BufferedReader; import java.io.IOException; import java.io.FileReader; import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { public static void readFileToList(String fileName, List<String> list) { readFileToList(new File(fileName), list); }//from w ww. j a v a2 s . c o m public static void readFileToList(File file, List<String> list) { try { BufferedReader in = new BufferedReader(new FileReader(file)); String s; while ((s = in.readLine()) != null) { list.add(s); } in.close(); } catch (Exception ex) { throw new RuntimeException(ex); } } public static List<String> readFileToList(String fileName) { return readFileToList(new File(fileName)); } public static List<String> readFileToList(File file) { List<String> list = new ArrayList<String>(); readFileToList(file, list); return list; } public static <S, T> void add(Map<S, List<T>> map, S key1, T key2) { List<T> s = map.get(key1); if (s == null) map.put(key1, s = new ArrayList<T>()); s.add(key2); } /** * Silently close a resource, returning any thrown exception. * @param c the resource to close, may be <code>null</code> * @return the thrown exception or <code>null</code> */ public static IOException close(Closeable c) { try { if (c != null) c.close(); } catch (IOException e) { return e; } return null; } }