Java BufferedReader Read readFile(String path)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String path) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String readFile(String path) {
        StringBuilder text = new StringBuilder();
        BufferedReader reader = null;

        try {//from   ww  w.  ja v a 2 s.  c o m
            reader = new BufferedReader(new FileReader(path));
            String line;

            while ((line = reader.readLine()) != null)
                text.append(line).append("\n");
        } catch (Exception ex) {
            throw new RuntimeException(ex.getMessage());
        }

        try {
            reader.close();
        } catch (IOException ex) {
            throw new RuntimeException(ex.getMessage());
        }

        return text.toString();
    }
}

Related

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