Java BufferedReader Read readFile(File file)

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

Description

read File

License

Open Source License

Declaration

public static String[] readFile(File file) 

Method Source Code

//package com.java2s;
/*Create easily accessible shortcuts to your favourite programs
 Copyright (C) 2014 xV3NoMzZz//from w w  w  .j a  v a2s  .  c om
    
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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(File file) {
        ArrayList<String> done = new ArrayList<String>();
        try (BufferedReader br = new BufferedReader(new FileReader(file))) {
            String current;
            while ((current = br.readLine()) != null) {
                done.add(current);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        String[] posRe = (String[]) done.toArray(new String[done.size()]);
        return posRe;
    }
}

Related

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