Java BufferedReader Read readFile(String fileName)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String fileName) throws IOException 

Method Source Code


//package com.java2s;
/* KIARA - Middleware for efficient and QoS/Security-aware invocation of services and exchange of messages
 *
 * Copyright (C) 2014 Proyectos y Sistemas de Mantenimiento S.L. (eProsima)
 *
 * This library 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.
 *
 * This library 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 this library. If not, see <http://www.gnu.org/licenses/>.
 *///w w w  . j a  v a2  s . co  m

import java.io.*;

public class Main {
    public static String readFile(String fileName) throws IOException {
        try (final BufferedReader br = new BufferedReader(new FileReader(fileName))) {
            final StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append("\n");
                line = br.readLine();
            }
            return sb.toString();
        }
    }
}

Related

  1. readFile(String filename)
  2. readFile(String filename)
  3. readFile(String fileName)
  4. readfile(String filename)
  5. readFile(String FileName)
  6. readFile(String filename, boolean print)
  7. readFile(String filename, boolean skipEmptyLine)
  8. readFile(String fileName, String basePath)
  9. readFile(String fileName, String commentFlag)