Java tutorial
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { public static String readFileContents(File file) throws IOException { StringBuilder sb = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new FileReader(file)); String currentLine; while ((currentLine = br.readLine()) != null) { sb.append(currentLine); sb.append('\n'); } } finally { if (br != null) { br.close(); } } return sb.toString(); } }