Java BufferedReader Read readFile(String fullPath)

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

Description

read File

License

Apache License

Declaration

public static String readFile(String fullPath) throws IOException 

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 fullPath) throws IOException {
        return readFile(new File(fullPath));
    }/*from  w  w  w  .  jav a  2  s  .co m*/

    public static String readFile(File file) throws IOException {
        BufferedReader reader = null;
        FileReader fr = null;
        StringBuilder builder = new StringBuilder("");
        try {
            fr = new FileReader(file);
            reader = new BufferedReader(fr);
            if (reader == null)
                return null;

            String line = null;
            while ((line = reader.readLine()) != null) {
                builder.append(line + "\n");
            }
        } finally {
            if (fr != null)
                fr.close();
            if (reader != null)
                reader.close();
        }
        return builder.toString();
    }
}

Related

  1. readFile(String filePath)
  2. readFile(String filePath)
  3. readFile(String filePath)
  4. readFile(String filePath)
  5. readFile(String filePath, Boolean replaceNewLineWithBr)
  6. readFile(String fullPath)
  7. readFile(String nameFile)
  8. readFile(String path)
  9. readFile(String path)