Java BufferedReader Read readFile(File f)

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

Description

Reads every line from a given text file.

License

Open Source License

Parameter

Parameter Description
f Input file.

Return

String[] Array containing each line in f.

Declaration

public static String[] readFile(File f) throws IOException 

Method Source Code

//package com.java2s;
/* Copyright (C) 2003 Univ. of Massachusetts Amherst, Computer Science Dept.
 This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit).
 http://www.cs.umass.edu/~mccallum/mallet
 This software is provided under the terms of the Common Public License,
 version 1.0, as published by http://www.opensource.org.  For further
 information, see the file `LICENSE' included with this distribution. */

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

public class Main {
    /**/*  w  ww  . java  2  s.c o  m*/
     * Reads every line from a given text file.
     * @param f Input file.
     * @return String[] Array containing each line in <code>f</code>.
     */
    public static String[] readFile(File f) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader(f));
        ArrayList list = new ArrayList();

        String line;
        while ((line = in.readLine()) != null)
            list.add(line);

        return (String[]) list.toArray(new String[0]);
    }
}

Related

  1. loadY(InputStream filePath)
  2. readFile(File f)
  3. readFile(File f)
  4. readFile(File f)
  5. readFile(File f)
  6. readFile(File f)
  7. readFile(File f)
  8. readFile(File f)
  9. readFile(File f)