Java Text File Read Line readLines(File inputFile)

Here you can find the source of readLines(File inputFile)

Description

Reads the contents of the given ascii file.

License

Open Source License

Parameter

Parameter Description
inputFile file to read

Return

each line is put in a separate String

Declaration

public static List<String> readLines(File inputFile) 

Method Source Code


//package com.java2s;
/* MOD_V2.0/* w  w w  . j  a  v a 2s.  co m*/
 * Copyright (c) 2012 OpenDA Association
 * All rights reserved.
 *
 * This file is part of OpenDA.
 *
 * OpenDA is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * OpenDA 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with OpenDA.  If not, see <http://www.gnu.org/licenses/>.
 */

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

public class Main {
    /**
     * Reads the contents of the given ascii file.
     *
     * @param inputFile file to read
     * @return each line is put in a separate String
     */
    public static List<String> readLines(File inputFile) {
        List<String> lines = new ArrayList<>();

        try {
            BufferedReader input = new BufferedReader(new FileReader(inputFile));
            try {
                String line = input.readLine();
                while (line != null) {
                    lines.add(line);
                    line = input.readLine();
                }
            } finally {
                input.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(
                    "Problem while reading file " + inputFile.getAbsolutePath() + " Message was " + e.getMessage(),
                    e);
        }

        return lines;
    }
}

Related

  1. readLines(File file, String charset)
  2. readLines(File file, String charsetName)
  3. readLines(File file, String encoding)
  4. readLines(File file, String encoding)
  5. readLines(File file, String outputLineEnding)
  6. readLines(File inputFile, String encoding)
  7. readLines(final File file)
  8. readlines(final File file)
  9. readLines(int problemNumber)