Java tutorial
//package com.java2s; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static String readFileAsString(String resource, boolean keepLineBreaks) throws IOException { BufferedReader reader = new BufferedReader( new InputStreamReader(ClassLoader.getSystemResourceAsStream("resources/" + resource))); StringBuffer resultString = new StringBuffer(); String line = null; while ((line = reader.readLine()) != null) { resultString.append(line); if (keepLineBreaks) { resultString.append("\n"); } } return resultString.toString(); } }