Here you can find the source of fileToString(String file, String encoding)
static public String fileToString(String file, String encoding) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.FileInputStream; public class Main { static public String fileToString(String file, String encoding) throws Exception { FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[10240]; int len = fis.read(buffer, 0, buffer.length); while (len > 0) { baos.write(buffer, 0, len);/*from w w w. jav a2 s.c o m*/ len = fis.read(buffer, 0, buffer.length); } fis.close(); return baos.toString(encoding); } }