Here you can find the source of getResourceAsString(String path)
public static String getResourceAsString(String path) throws Exception
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; public class Main { public static String getResourceAsString(String path) throws Exception { InputStream is = ClassLoader.getSystemResourceAsStream(path); BufferedReader br = null; StringBuilder sb = new StringBuilder(); String line;/*from w w w. jav a2 s .co m*/ try { br = new BufferedReader(new InputStreamReader(is)); while ((line = br.readLine()) != null) { sb.append(line).append('\n'); } } finally { if (br != null) { br.close(); } is.close(); } return sb.toString(); } }