Here you can find the source of readTextFile(File file)
public static String readTextFile(File file)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.Scanner; public class Main { public static String readTextFile(File file) { try {/* w w w .j av a 2s . co m*/ return readText(new FileInputStream(file)); } catch (Exception e) { throw new RuntimeException("Reading text file \"" + file + "\" failed", e); } } public static String readText(InputStream in) { StringBuilder text = new StringBuilder(); Scanner scanner = new Scanner(in); while (scanner.hasNextLine()) { text.append(scanner.nextLine() + "\n"); } return text.toString(); } }