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) 

Method Source Code


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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    public static String readFile(String fileName) {
        File file = new File(fileName);

        if (!file.exists()) {
            return null;
        } //if/* www. j ava  2s.c om*/

        BufferedReader br = null;
        StringBuilder res = new StringBuilder();
        try {

            String sCurrentLine;

            br = new BufferedReader(new FileReader(file));

            while ((sCurrentLine = br.readLine()) != null) {
                res.append(sCurrentLine);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null)
                    br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        } //finally

        return res.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)