Java FileReader Read readFile(File file)

Here you can find the source of readFile(File file)

Description

Helper function to read the contents of a file and return a string represntation.

License

Open Source License

Parameter

Parameter Description
file input file

Exception

Parameter Description
IOException an exception

Declaration

private static String readFile(File file) throws IOException 

Method Source Code


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

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

public class Main {
    /**/*  ww  w. j a  v a 2  s.co  m*/
     * Helper function to read the contents of a file and return a string represntation.
     *
     * @param file input file
     *
     * @throws IOException
     */
    private static String readFile(File file) throws IOException {
        FileReader fileReader = new FileReader(file);

        StringBuffer content = new StringBuffer();

        int read = fileReader.read();
        while (read != -1) {
            content.append((char) read);
            read = fileReader.read();
        }
        return content.toString();
    }
}

Related

  1. readFile(File file)
  2. readFile(File file)
  3. readFile(File file)
  4. readFile(File file)
  5. readFile(File file)
  6. readFile(File file)
  7. readFile(File file)
  8. readFile(File iFile)
  9. readFile(final String fileName)