Java tutorial
//package com.java2s; import java.io.*; public class Main { public static String file2String(File file) { FileInputStream fis = null; ByteArrayOutputStream baos = null; try { fis = new FileInputStream(file); baos = new ByteArrayOutputStream(); int i; while ((i = fis.read()) != -1) { baos.write(i); } String str = baos.toString(); return str; } catch (FileNotFoundException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } finally { try { if (fis != null) fis.close(); if (baos != null) baos.close(); } catch (IOException e) { e.printStackTrace(); } } } }