Java BufferedReader Read All readAll(File file)

Here you can find the source of readAll(File file)

Description

Simple method to read all the contents of a file

License

Open Source License

Parameter

Parameter Description
file File to read

Exception

Parameter Description
IOException an exception

Return

The contents

Declaration

public static List<String> readAll(File file) throws IOException 

Method Source Code


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

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*from   w  w w  .  java  2s.  c o  m*/
     * Simple method to read all the contents of a file
     * @param file File to read
     * @return The contents
     * @throws IOException
     */
    public static List<String> readAll(File file) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader(file));
        List<String> lines = new ArrayList<String>();
        while (reader.ready())
            lines.add(reader.readLine());
        reader.close();
        return lines;
    }
}

Related

  1. readAll(File f)
  2. readAll(File file)
  3. readAll(File file)
  4. readAll(File input)
  5. readAll(final Reader reader)