Here you can find the source of readFile(String filename1)
public static String readFile(String filename1) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static String readFile(String filename1) throws IOException { File f = new File(filename1); if (!f.exists()) return null; FileInputStream fis = null; InputStreamReader fsr = null; StringBuilder out = new StringBuilder(); int len;/* w w w .ja v a 2 s. c om*/ char[] buffer = new char[1024]; try { fis = new FileInputStream(filename1); fsr = new InputStreamReader(fis, "UTF-8"); while (true) { len = fsr.read(buffer); if (len == -1) break; out.append(buffer, 0, len); } } finally { try { if (fsr != null) fsr.close(); } catch (Exception e) { e.printStackTrace(); } try { if (fis != null) fis.close(); } catch (Exception e) { e.printStackTrace(); } } return out.toString(); } }