Java Text File Read fileContentsToString(File errFile)

Here you can find the source of fileContentsToString(File errFile)

Description

Utility method to read in contents of file and concatenate into String

License

Open Source License

Parameter

Parameter Description
errFile File to be read

Exception

Parameter Description
IOException an exception

Return

String containing contents of file

Declaration

public static String fileContentsToString(File errFile) throws IOException 

Method Source Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    /**//from   w w  w . j  a v  a2s.co  m
     * Utility method to read in contents of file and concatenate into String
     * @param errFile File to be read
     * @return String containing contents of file
     * @throws IOException
     */
    public static String fileContentsToString(File errFile) throws IOException {
        String errFileString = null;
        BufferedReader br = null;
        StringBuffer sb = new StringBuffer();
        br = new BufferedReader(new FileReader(errFile));
        String errLine = br.readLine();
        while (errLine != null) {
            sb.append(errLine);
            errLine = br.readLine();
        }
        errFileString = sb.toString();
        return errFileString;
    }
}

Related

  1. fileAsString(File file)
  2. fileAsString(String fileName)
  3. fileAsString(String filePath)
  4. fileContentsToString(String file)
  5. getChars(File file)
  6. getChars(Reader r)
  7. getFileContentAsString(File cpfile)