Here you can find the source of readFile(String pathname)
Parameter | Description |
---|---|
pathname | a String, the path of the file on the machine |
Parameter | Description |
---|---|
IOException | if the file at pathname cannot be read |
public static List<String> readFile(String pathname) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Main { /**/*from w w w .j a v a2 s. c o m*/ * Reads the file at the specified pathname and returns it as a List of * Strings, one per line of the file. The newline terminators will be * stripped from each line when stored. * * @param pathname a String, the path of the file on the machine * @return a List of Strings representing the lines of the file * at the specified pathname * @throws IOException if the file at pathname cannot be read */ public static List<String> readFile(String pathname) throws IOException { List<String> lines = new ArrayList<>(); BufferedReader reader = new BufferedReader(new FileReader(pathname)); while (reader.ready()) { lines.add(reader.readLine()); } reader.close(); return lines; } }