Java BufferedReader Read readFile(File f)

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

Description

Reads the content of a file and returns an ArrayList with the data

License

Open Source License

Parameter

Parameter Description
f File that should be read

Return

ArrayList of data

Declaration

public static List<String> readFile(File f) 

Method Source Code


//package com.java2s;
/*//from   w  w  w  .  j a v a  2 s .c  om
* Copyright (c) 2010-2012 Research In Motion Limited. All rights reserved.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License, Version 1.0,
* which accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*
*/

import java.io.BufferedReader;
import java.io.File;

import java.io.FileNotFoundException;

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Reads the content of a file and returns an ArrayList with the data
     *
     * @param f
     *            File that should be read
     * @return ArrayList of data
     */
    public static List<String> readFile(File f) {
        List<String> data = new ArrayList<String>();

        try {
            BufferedReader br = new BufferedReader(new FileReader(f));
            while (br.ready()) {
                data.add(br.readLine());
            }
            return data;
        } catch (FileNotFoundException e) {
            return null;
        } catch (IOException e) {
            return null;
        }
    }
}

Related

  1. readFile(File f)
  2. readFile(File f)
  3. readFile(File f)
  4. readFile(File f)
  5. readFile(File f)
  6. ReadFile(File f, boolean keep_newline)
  7. readFile(File f, boolean preserveLineBreaks)
  8. readFile(File f, String newLineChar)
  9. readFile(File file)