Java BufferedReader Read readFile(File testPage)

Here you can find the source of readFile(File testPage)

Description

Read a file into a List

License

Open Source License

Parameter

Parameter Description
testPage a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static List<String> readFile(File testPage) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import static com.google.common.collect.Lists.newArrayList;
import java.io.BufferedReader;
import java.io.File;

import java.io.FileReader;
import java.io.IOException;

import java.util.List;

public class Main {
    /**/*  w  w w . j  a  v a  2  s  .c  om*/
     * Read a file into a List<String>
     * @param testPage
     * @return
     * @throws IOException
     */
    public static List<String> readFile(File testPage) throws IOException {
        BufferedReader reader = null;
        try {
            List<String> lines = newArrayList();
            FileReader fr = new FileReader(testPage);
            reader = new BufferedReader(fr);
            String line = reader.readLine();
            while (line != null) {
                lines.add(line);
                line = reader.readLine();
            }
            return lines;
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
    }
}

Related

  1. readFile(File from)
  2. readFile(File in)
  3. readFile(File inputFile)
  4. readFile(File location)
  5. readFile(File path)
  6. readFile(final File argFile)
  7. readFile(final File file)
  8. readFile(final File file)
  9. readFile(final File file)