Java BufferedReader Read readFile(File path)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(File path) 

Method Source Code


//package com.java2s;
//License from project: Open Source 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 path) {
        try {/*w  ww  .j  a va  2s .c o m*/
            String line = null;
            StringBuilder stringBuilder = new StringBuilder();
            String ls = System.getProperty("line.separator");
            BufferedReader reader = new BufferedReader(new FileReader(path));
            try {
                while ((line = reader.readLine()) != null) {
                    stringBuilder.append(line);
                    stringBuilder.append(ls);
                }

                return stringBuilder.toString();
            } finally {
                try {
                    reader.close();
                } catch (IOException ignore) {
                }
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}

Related

  1. readFile(File filename)
  2. readFile(File from)
  3. readFile(File in)
  4. readFile(File inputFile)
  5. readFile(File location)
  6. readFile(File testPage)
  7. readFile(final File argFile)
  8. readFile(final File file)
  9. readFile(final File file)