Java BufferedReader Read ReadFile(File f, boolean keep_newline)

Here you can find the source of ReadFile(File f, boolean keep_newline)

Description

Read File

License

Open Source License

Declaration

public static String ReadFile(File f, boolean keep_newline) 

Method Source Code

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

import java.io.*;

public class Main {
    public static String ReadFile(File f) {
        return ReadFile(f, false);
    }/*from w  w  w .  j ava 2  s . co  m*/

    public static String ReadFile(File f, boolean keep_newline) {
        try {
            StringBuilder sb = new StringBuilder();
            java.io.BufferedReader br = new BufferedReader(
                    new FileReader(f));
            String line = null;
            while ((line = br.readLine()) != null) {
                //System.out.println(line);
                sb.append((sb.length() > 0 ? (keep_newline ? "\n" : " ")
                        : "") + line);
            }
            br.close();
            return sb.toString();
        } catch (Exception e) {
            System.out.println("ERROR: " + e);
            return null;
        }
    }
}

Related

  1. readFile(File f)
  2. readFile(File f)
  3. readFile(File f)
  4. readFile(File f)
  5. readFile(File f)
  6. readFile(File f, boolean preserveLineBreaks)
  7. readFile(File f, String newLineChar)
  8. readFile(File file)
  9. readFile(File file)