Here you can find the source of readTextFile(final String path, final String enc)
public static String readTextFile(final String path, final String enc) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static String readTextFile(final String path, final String enc) throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); try {//from ww w . j a v a2 s . c o m File f = new File(path); if (f.exists()) { FileInputStream is = new FileInputStream(path); try { copyStream(is, os); } finally { is.close(); } } else { return null; } } finally { os.close(); } return new String(os.toByteArray(), enc); } public static void copyStream(final InputStream is, final OutputStream os) throws IOException { byte[] buf = new byte[16 * 1024]; while (true) { int len = is.read(buf); if (len <= 0) { break; } os.write(buf, 0, len); } } public static void copyStream(final InputStream is, final OutputStream os, final boolean close) throws IOException { try { try { copyStream(is, os); } finally { if (close) { os.close(); } } } finally { if (close) { is.close(); } } } }