Here you can find the source of readFile(String filePath)
public static synchronized String readFile(String filePath) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { public static synchronized String readFile(String filePath) throws IOException { byte[] data = new byte[0]; FileInputStream fileInputStream = null; try {//ww w . j a va 2s.co m File file = new File(filePath); fileInputStream = new FileInputStream(new File(filePath)); data = new byte[(int) file.length()]; fileInputStream.read(data); } finally { closeResource(fileInputStream); } return new String(data, "UTF-8"); } public static void closeResource(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (IOException e) { // ignore } } } }