Java BufferedReader Read readFile(String aFileName)

Here you can find the source of readFile(String aFileName)

Description

read File

License

Open Source License

Declaration

public static String[] readFile(String aFileName) throws IOException 

Method Source Code


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

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

import java.util.ArrayList;

public class Main {
    public static String[] readFile(String aFileName) throws IOException {
        File aFile = new File(aFileName);
        BufferedReader input = new BufferedReader(new FileReader(aFile));
        ArrayList<String> outputBuffer = new ArrayList<String>();
        try {/*  w  ww  .j  a  v a2  s  .c  o  m*/
            String line = null; //not declared within while loop
            while ((line = input.readLine()) != null) {
                outputBuffer.add(line);
            }
        } finally {
            input.close();
        }
        int nlines = outputBuffer.size();
        String[] status = null;
        if (nlines < 1) {
            status = new String[1];
            status[0] = "";
        } else {
            status = new String[nlines];
            for (int il = 0; il < nlines; ++il) {
                status[il] = outputBuffer.get(il);
            }
        }
        return status;
    }
}

Related

  1. readFile(final String path)
  2. readFile(final String pFile)
  3. readFile(List fieldNames, String filename)
  4. readFile(Reader reader)
  5. readFile(String absoluteFilePath)
  6. readFile(String directory)
  7. readFile(String directory, String fileName)
  8. readFile(String file)
  9. readFile(String file)