Java BufferedReader Read readFile(String filePath, Boolean replaceNewLineWithBr)

Here you can find the source of readFile(String filePath, Boolean replaceNewLineWithBr)

Description

read File

License

Open Source License

Declaration

public static String readFile(String filePath, Boolean replaceNewLineWithBr) throws IOException 

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 filePath, Boolean replaceNewLineWithBr) throws IOException {
        String result = null;/*from  w w  w  .  jav a 2  s  . c om*/
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        StringBuilder sb = new StringBuilder();
        String line = br.readLine();
        while (line != null) {
            sb.append(line);
            if (replaceNewLineWithBr) {
                sb.append("<br>");
            } else {
                sb.append('\n');
            }
            line = br.readLine();
        }
        result = sb.toString();
        br.close();
        return result;
    }
}

Related

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