The readFile(...) method presented below reads a file and returns the string with the content. We have used StringBuffer to perform concatenation operations.
private static String readFile(String filename) throws IOException {
String lineSep = System.getProperty("line.separator");
BufferedReader br = new BufferedReader(new FileReader(filename));
String nextLine = "";
StringBuffer sb = new StringBuffer();
while ((nextLine = br.readLine()) != null) {
sb.append(nextLine);
sb.append(lineSep);
}
return sb.toString();
}