Java BufferedReader Read readFile(File filename)

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

Description

reads file into ArrayList.

License

Open Source License

Parameter

Parameter Description
filename full path

Declaration

public static ArrayList<String> readFile(File filename) 

Method Source Code

//package com.java2s;
/** /*from  ww w . ja  v  a  2 s  .  co  m*/
 * IOUtils.java
 * 
 * Copyright (c) 2006, JULIE Lab. 
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0 
 *
 * Author: tomanek
 * 
 * Current version: 2.3
 * Since version:   2.2
 *
 * Creation date: Nov 1, 2006 
 * 
 * Some more utils for JNET.
 * 
 **/

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

import java.io.IOException;
import java.util.ArrayList;

public class Main {
    /**
     * reads file into ArrayList. Each line is one element (String).
     * 
     * @param filename
     *            full path
     */
    public static ArrayList<String> readFile(File filename) {
        ArrayList<String> lines = new ArrayList<String>();
        try {
            BufferedReader br = new BufferedReader(new FileReader(filename));
            try {
                String line = "";
                while ((line = br.readLine()) != null) {
                    lines.add(line);
                }
                br.close();
            } catch (IOException e) {
                System.err.println("Read error " + e);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return lines;
    }
}

Related

  1. readFile(File file)
  2. readFile(File file)
  3. readFile(File file)
  4. readFile(File file, boolean useSystemLineSeparator)
  5. readFile(File file, int header)
  6. readFile(File from)
  7. readFile(File in)
  8. readFile(File inputFile)
  9. readFile(File location)