Here you can find the source of fileToString(String pathname)
private static String fileToString(String pathname) throws IOException
//package com.java2s; //License from project: Creative Commons License import java.io.File; import java.io.IOException; import java.util.Scanner; public class Main { private static String fileToString(String pathname) throws IOException { File file = new File(pathname); StringBuilder fileContents = new StringBuilder((int) file.length()); Scanner scanner = new Scanner(file); String lineSeparator = System.getProperty("line.separator"); try {/*from w w w . java 2 s. c om*/ while (scanner.hasNextLine()) { fileContents.append(scanner.nextLine() + lineSeparator); } return fileContents.toString(); } finally { scanner.close(); } } }