Here you can find the source of readFile(String file)
public static String readFile(String file) throws IOException
//package com.java2s; //License from project: LGPL import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static String readFile(String file) throws IOException { return readFile(file, null); }/* w w w. j av a 2 s . com*/ public static String readFile(String file, String charset) throws IOException { File f = new File(file); if (!f.exists()) return null; FileInputStream fis = null; BufferedReader br = null; try { fis = new FileInputStream(f); if (charset != null) { br = new BufferedReader(new InputStreamReader(fis, charset)); } else { br = new BufferedReader(new InputStreamReader(fis)); } StringBuilder sb = new StringBuilder(1024); String line; while ((line = br.readLine()) != null) { sb.append(line).append('\n'); } return sb.toString(); } finally { br.close(); } } }