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;
/*******************************************************************************
 * Copyright (c) 2015 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from   ww w.ja v  a 2  s .  c o m*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

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

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

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)
  7. readFile(String filename)
  8. readFile(String fileName)
  9. readFile(String fileName)