Java BufferedReader Read readFileContext(File fileToRead)

Here you can find the source of readFileContext(File fileToRead)

Description

Read the context of a file.

License

Open Source License

Parameter

Parameter Description
fileToRead the file to read

Return

the context of the file

Declaration

private static String readFileContext(File fileToRead) 

Method Source Code


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

public class Main {
    /**//w  w w  .j  av a2 s  .c  o  m
     * <p>
     * Represents the line separator.
     * </p>
     */
    public static final String LINE_SEP = System.getProperty("line.separator");

    /**
     * <p>
     * Read the context of a file.
     * </p>
     *
     * @param fileToRead
     *            the file to read
     * @return the context of the file
     */
    private static String readFileContext(File fileToRead) {
        try {
            BufferedReader bf = new BufferedReader(new FileReader(fileToRead));
            StringBuffer sb = new StringBuffer();
            String aline = bf.readLine();
            while (aline != null) {
                sb.append(aline);
                sb.append(LINE_SEP);
                aline = bf.readLine();
            }
            bf.close();
            return sb.toString();
        } catch (Exception e) {
            return null;
        }
    }
}

Related

  1. readFileAsListOfString(String fileName, String splitBy)
  2. readFileAsListOfStrings(String filename)
  3. readFileAsListOfStrings(String filename)
  4. readFileAsText(String path)
  5. readFileByChar(String path)
  6. readFileEncoding(String file)
  7. readFileGdeHash(File gdeFile, ArrayList name, ArrayList seq)
  8. readFilePathToString(String filePath)
  9. readFileToHashMap(String filePath, String separator, boolean valueFirst)