Here you can find the source of getResourceAsString(Class> theClass, String fileName)
public static String getResourceAsString(Class<?> theClass, String fileName) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { public static String getResourceAsString(Class<?> theClass, String fileName) throws IOException { File f = new File(theClass.getResource(fileName).getFile()); FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr); StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line + "\n"); line = br.readLine();//from ww w . ja va2 s . c o m } return sb.toString(); } }