Java Text File Read getFileContents(String pathToFile)

Here you can find the source of getFileContents(String pathToFile)

Description

FileUtils.getFileContents() Returns the content of a file as a String

License

Open Source License

Parameter

Parameter Description
pathToFile a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static String getFileContents(String pathToFile)
        throws IOException 

Method Source Code

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

import java.io.*;

public class Main {
    /**/*from w ww .  java 2s.c om*/
     * FileUtils.getFileContents()
     *
     * Returns the content of a file as a String
     *
     * @param pathToFile
     * @return
     * @throws IOException
     */
    public static String getFileContents(String pathToFile)
            throws IOException {
        BufferedReader br = null;
        String content = "";

        try {

            String sCurrentLine;

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

            while ((sCurrentLine = br.readLine()) != null) {
                content += sCurrentLine + "\r\n";
            }

        } finally {
            if (br != null)
                br.close();
        }

        return content;
    }
}

Related

  1. getFileContents(String filePath)
  2. getFileContents(String filePath)
  3. getFileContents(String filePath)
  4. getFileContents(String filePath)
  5. getFileContents(String path)
  6. getFileContents(String pFileName)
  7. loadAsString(String location)
  8. readFile(String filePath)
  9. readFile(String path)