Java BufferedReader Read readFile(File file)

Here you can find the source of readFile(File file)

Description

Reads a file and returns its content as a String.

License

Open Source License

Declaration

public static String readFile(File file) throws Exception 

Method Source Code

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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class Main {
    /**/* w  ww  . j  a  v  a  2  s. c o  m*/
     * Reads a file and returns its content as a String.
     * 
     * @author pedro.costa@xseed.com.br
     */
    public static String readFile(File file) throws Exception {
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String line = null;
        StringBuilder stringBuilder = new StringBuilder();
        String ls = System.getProperty("line.separator");

        while ((line = reader.readLine()) != null) {
            stringBuilder.append(line);
            stringBuilder.append(ls);
        }

        reader.close();

        return stringBuilder.toString();
    }
}

Related

  1. readFile(File file)
  2. readFile(File file)
  3. readFile(File file)
  4. readFile(File file)
  5. readFile(File file)
  6. readFile(File file)
  7. readFile(File file)
  8. readFile(File file)
  9. readFile(File file)