Java tutorial
//package com.java2s; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { /** * get the file contents from resource as string * @param aFileName file name * @param aRetrieverClass retriever class * @return * @throws IOException */ public static String GetFileContentFromResourceAsString(String aFileName, Class aRetrieverClass) throws IOException { InputStream input = null; BufferedReader bReader = null; try { // read all the file content StringBuffer buffer = new StringBuffer(); input = aRetrieverClass.getResourceAsStream(aFileName); InputStreamReader isr = new InputStreamReader(input); bReader = new BufferedReader(isr); String line; while ((line = bReader.readLine()) != null) { buffer.append(line); buffer.append(System.getProperty("line.separator")); } return buffer.toString(); } finally { if (bReader != null) bReader.close(); if (input != null) input.close(); } } }