Here you can find the source of readFile(String filename)
public static String readFile(String filename)
//package com.java2s; /******************************************************************************* * Copyright ? 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/* w w w. j av a2s. com*/ * IBM Corporation - initial API and implementation * *******************************************************************************/ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Main { public static String readFile(String filename) { try { BufferedReader reader = new BufferedReader(new FileReader(filename)); StringBuffer buffer = new StringBuffer(); // Print the first line String line = reader.readLine(); if (line != null) { buffer.append(line); // Print subsequent lines while (true) { line = reader.readLine(); if (line == null) break; buffer.append("\r\n"); buffer.append(line); } } reader.close(); return buffer.toString(); } catch (FileNotFoundException e) { System.err.println("Testcase not found"); } catch (IOException e) { System.err.println("Error reading testcase file"); } return null; } }