Java BufferedReader Read readFile(String path)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String path) throws IOException 

Method Source Code

//package com.java2s;
/**/*from   w  ww  .  java 2s  . c  om*/
 *  Copyright (C) 2008 Progress Software, Inc. All rights reserved.
 *  http://fusesource.com
 *
 *  The software in this package is published under the terms of the AGPL license
 *  a copy of which has been included with this distribution in the license.txt file.
 */

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

public class Main {
    public static final int BUFFER_SIZE = 1024;

    public static String readFile(String path) throws IOException {
        return readFile(new File(path));
    }

    public static String readFile(File file) throws IOException {

        StringBuilder sb = new StringBuilder();

        BufferedReader reader = new BufferedReader(new FileReader(file));

        char[] chars = new char[BUFFER_SIZE];
        int length;

        while ((length = reader.read(chars)) > 0) {
            sb.append(chars, 0, length);
        }

        reader.close();
        return sb.toString();
    }
}

Related

  1. readFile(String path)
  2. readFile(String path)
  3. readFile(String path)
  4. readFile(String path)
  5. readFile(String path)
  6. readFile(String path)
  7. readFile(String path)
  8. readFile(String path)
  9. readFile(String pathname)