Here you can find the source of getResourceAsString(String relativePath)
public static String getResourceAsString(String relativePath)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; import java.util.Scanner; public class Main { public static String getResourceAsString(String relativePath) { InputStream inputStream = Thread.currentThread() .getContextClassLoader().getResourceAsStream(relativePath); Scanner s = new Scanner(inputStream, "UTF-8"); Scanner s2 = s.useDelimiter("\\A"); String result = s2.hasNext() ? s2.next() : ""; s.close();/*w w w .jav a 2 s . com*/ s2.close(); try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } return result; } }