Here you can find the source of readFile(File file)
public static String readFile(File file)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Main { public static String readFile(File file) { StringBuilder fileContents = new StringBuilder(); Scanner scanner;//w w w . j a va 2 s .com try { scanner = new Scanner(file, "UTF-8"); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } String lineSeparator = System.getProperty("line.separator"); try { while (scanner.hasNextLine()) { fileContents.append(scanner.nextLine() + lineSeparator); } return fileContents.toString(); } finally { scanner.close(); } } }