Java File Read getFileContent(final File srcFile)

Here you can find the source of getFileContent(final File srcFile)

Description

Returns the content of a file as string.

License

Open Source License

Parameter

Parameter Description
srcFile File

Exception

Parameter Description
IOException an exception

Return

String

Declaration

public static String getFileContent(final File srcFile) throws IOException 

Method Source Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

public class Main {
    /**/*from w  w w . j ava 2  s . com*/
     * Returns the content of a file as string.
     * 
     * @param srcFile
     *            File
     * @return String
     * @throws IOException
     */
    public static String getFileContent(final File srcFile) throws IOException {
        if ((srcFile != null) && srcFile.exists() && srcFile.isFile()) {
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(srcFile)));
            StringBuffer contentOfFile = new StringBuffer();
            String line;
            while ((line = br.readLine()) != null) {
                contentOfFile.append(line);
            }
            return contentOfFile.toString();
        }
        return null;
    }
}

Related

  1. getFileContent(File file, int bufferSize)
  2. getFileContent(File pFile)
  3. getFileContent(final File f)
  4. getFileContent(final File file)
  5. getFileContent(final String fileName)
  6. getFileContent(final String p_filename)
  7. getFileContentAsAString(final File aFile)
  8. getFileContentAsList(String filePath)