Here you can find the source of readFileContext(File fileToRead)
Read the context of a file.
Parameter | Description |
---|---|
fileToRead | the file to read |
private static String readFileContext(File fileToRead)
//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; } } }