Java FileReader Create readTextFile(String filePath)

Here you can find the source of readTextFile(String filePath)

Description

read Text File

License

Open Source License

Declaration

public static String readTextFile(String filePath) 

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 readTextFile(String filePath) {
        String str = null;//from w w w. j a va  2 s  .  c  om
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader(filePath));
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append("\n");
                line = br.readLine();
            }
            str = sb.toString();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return str;
    }
}

Related

  1. readTextFile(String filename)
  2. readTextFile(String filename)
  3. readTextFile(String fileName, boolean newline)
  4. readTextFile(String fileName, String enc)
  5. readTextFile(String filePath)
  6. readTextFile(String filePath)
  7. readTextFile(String fullPathFilename)
  8. readTextFile(String path)
  9. readTextFile(String path)