Java tutorial
//package com.java2s; // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Main { /** * Reads content of file, and returns result as string * * @param filename path to file * @return Contents of file * @throws IOException */ public static String fileToString(String filename) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(filename)); StringBuilder builder = new StringBuilder(); String line; // For every line in the file, append it to the string builder while ((line = reader.readLine()) != null) { builder.append(line); } reader.close(); return builder.toString(); } }