Java BufferedReader Read readFile(File f)

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

Description

read File

License

Apache License

Declaration

public static String readFile(File f) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

import java.io.FileReader;

import java.io.IOException;

public class Main {
    public static String readFile(File f) throws IOException {
        BufferedReader br = null;
        try {//from  w  w  w . j a v a 2  s  .com
            br = new BufferedReader(new FileReader(f));
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();
            while (line != null) {
                sb.append(line);
                line = br.readLine();
                if (line != null) {
                    sb.append("\n");
                }
            }
            return sb.toString();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    throw (e);
                }
            }
        }

    }
}

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)
  7. readFile(File f)
  8. readFile(File f)
  9. readFile(File f)