Java File Content Read getFileContents(File f)

Here you can find the source of getFileContents(File f)

Description

getFileContents Build a string by concatenating all lines in File object.

License

Apache License

Parameter

Parameter Description
f File object

Return

String

Declaration

public static String getFileContents(File f) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    static final String lineSep = System.getProperty("line.separator");

    /**//  ww  w  .j  av  a2 s.c o  m
     * getFileContents
     *
     * Build a string by concatenating all lines in File object.
     *
     * @param f File object
     * @return String
     */
    public static String getFileContents(File f) throws Exception {
        FileReader fr = new FileReader(f);
        BufferedReader br = new BufferedReader(fr);
        StringBuilder contents = new StringBuilder();
        String line;

        while ((line = br.readLine()) != null) {
            contents.append(line + lineSep);
        }

        br.close();
        return contents.toString();
    }
}

Related

  1. getFileContent(String path)
  2. getFileContent(String path)
  3. getFileContent(String path, String encoding)
  4. getFileContent(String pythonSource)
  5. getFileContents(File f)
  6. getFileContents(File file)
  7. getFileContents(File file)
  8. getFileContents(File methodPatch)
  9. getFileContents(File testFile)