Java BufferedReader Read readFile(String path)

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

Description

Read file.

License

Open Source License

Parameter

Parameter Description
path the path

Return

the string

Declaration

public static String readFile(String path) 

Method Source Code


//package com.java2s;
/*/*from   w ww.  ja v a 2 s.  c  o  m*/
 * FileReaderUtil.java
 * Copyright (c) 2013, EcoFactor, All Rights Reserved.
 *
 * This software is the confidential and proprietary information of EcoFactor
 * ("Confidential Information"). You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you entered into with
 * EcoFactor.
 */

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

public class Main {
    /**
     * Read file.
     * @param path the path
     * @return the string
     */
    public static String readFile(String path) {

        StringBuilder content = new StringBuilder();
        BufferedReader br = null;

        try {

            String sCurrentLine;

            br = new BufferedReader(new FileReader(path));

            while ((sCurrentLine = br.readLine()) != null) {
                content.append(sCurrentLine);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null)
                    br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }

        return content.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 path)