Java BufferedReader Read readFile(String fileName)

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

Description

read File

License

Apache License

Declaration

public static String readFile(String fileName) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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));
        StringBuilder everything = new StringBuilder();

        String line = "";
        try {/*w ww .  ja  v  a  2  s .c  o m*/

            line = br.readLine();
            while (line != null) {
                everything.append(line + "\n");
                line = br.readLine();
            }
        } catch (Exception ex) {
            System.out.println("Line Error: " + line);
            ex.printStackTrace();
        } finally {
            br.close();
        }
        return everything.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)
  7. readFile(String fileName)
  8. readFile(String filename)
  9. readFile(String filename)