Here you can find the source of fileToString(String filename)
public static String fileToString(String filename)
//package com.java2s; //License from project: Apache License import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; public class Main { public static String fileToString(String filename) { String result = null;/*from w ww. j a va 2 s.c o m*/ DataInputStream in = null; try { byte[] buffer = new byte[(int) new File(filename).length()]; in = new DataInputStream(new FileInputStream(filename)); in.readFully(buffer); result = new String(buffer); in.close(); } catch (Exception e) { e.printStackTrace(); } return result; } }