Here you can find the source of readFile(Class ownerClass, String fileName)
public static String readFile(Class ownerClass, String fileName) throws IOException
//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 readFile(Class ownerClass, String fileName) throws IOException { String resourcePath = ownerClass.getSimpleName() + "/" + fileName; try (InputStream inputStream = ownerClass.getResourceAsStream(resourcePath); Scanner scanner = new Scanner(inputStream)) { scanner.useDelimiter("\\A"); return scanner.hasNext() ? scanner.next() : ""; }// w w w . j a v a2s .c o m } }