Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static String getFileContent(File file) { FileInputStream fis = null; try { fis = new FileInputStream(file); return getInputStreamString(fis); } catch (IOException e) { e.printStackTrace(); return null; } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { // ignore } } } } public static String getInputStreamString(InputStream is) throws IOException { byte[] buffer = new byte[is.available()]; int len = is.read(buffer); return new String(buffer, 0, len, "utf-8"); } }