Here you can find the source of readFileIntoLines(File file)
Parameter | Description |
---|---|
file | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static List<String> readFileIntoLines(File file)
//package com.java2s; /**//w w w . j a v a 2 s . c o m * <p> * Utilities for manipulating Paths, Files, Directories, etc. * </p> * <p> * <span class="BSDLicense"> This software is distributed under the <a * href="http://hci.stanford.edu/research/copyright.txt">BSD License</a>.</span> * </p> * * @author <a href="http://graphics.stanford.edu/~ronyeh">Ron B Yeh</a> (ronyeh(AT)cs.stanford.edu) */ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Main { /** * Reads a file into a list of Strings * * @param file * @return * @throws IOException */ public static List<String> readFileIntoLines(File file) { List<String> lines = new ArrayList<String>(); try { FileInputStream fis = new FileInputStream(file); BufferedReader read = new BufferedReader(new InputStreamReader(fis)); String line; while ((line = read.readLine()) != null) { lines.add(line); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return lines; } }