Here you can find the source of readFileAsList(final String filename)
Parameter | Description |
---|---|
filename | the name of the file to read |
public static List<String> readFileAsList(final String filename)
//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 { /**//from w ww .ja v a 2s . c o m * @param filename * the name of the file to read * @return the contents of the file, as a {@code List<String>} of lines */ public static List<String> readFileAsList(final String filename) { final File f = new File(filename); if (f.exists()) { return readFileAsList(f); } return null; } /** * @param file * the {@code File} to read * @return the contents of the file, as a {@code List<String>} of lines */ public static List<String> readFileAsList(final File file) { final List<String> contents = new ArrayList<String>(); try { final BufferedReader br = new BufferedReader(new FileReader(file)); String line; while ((line = br.readLine()) != null) { contents.add(new String(line)); } br.close(); } catch (final IOException e) { e.printStackTrace(); return null; } return contents; } }