Here you can find the source of readTxtFromFile(File file)
public static String readTxtFromFile(File file) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.nio.ByteBuffer; public class Main { public static String readTxtFromFile(File file) throws Exception { ByteBuffer buffer = ByteBuffer.allocate((int) file.length()); FileInputStream in = new FileInputStream(file); in.getChannel().read(buffer);/* w w w .ja v a 2s . co m*/ in.close(); return new String(buffer.array()); } }