Java tutorial
//package com.java2s; //Software released under Common Public License (CPL) v1.0 import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { public static String getFileContent(File file) { FileInputStream f = null; try { byte[] buffer = new byte[(int) file.length()]; f = new FileInputStream(file); f.read(buffer); return new String(buffer); } catch (IOException e) { throw new RuntimeException(e); } finally { closeAll(f); } } public static void closeAll(Closeable... closeables) { if (closeables != null) { for (Closeable c : closeables) { try { c.close(); } catch (Exception e) { // empty } } } } }