Here you can find the source of readFile(String path)
static String readFile(String path) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.*; import java.nio.channels.FileChannel; import java.nio.charset.Charset; public class Main { static String readFile(String path) throws IOException { FileInputStream stream = new FileInputStream(new File(path)); try {//from w w w. j a va 2s . c om FileChannel fc = stream.getChannel(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); return Charset.defaultCharset().decode(bb).toString(); } finally { stream.close(); } } }