Here you can find the source of fileToString(File file, int max)
public static String fileToString(File file, int max) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; public class Main { public static String fileToString(File file, int max) throws IOException { if (!file.exists() && file.canRead()) { throw new IllegalStateException("File " + file.getName() + " either does not exist or can not be read"); }/*from www.j a va 2 s . c om*/ RandomAccessFile raf = new RandomAccessFile(file, "r"); if (raf.length() > max) { raf.close(); throw new IllegalStateException("File " + file.getName() + " is to large (>" + max); } byte[] ba = new byte[(int) raf.length()]; raf.read(ba); raf.close(); return new String(ba); } }