Here you can find the source of readFile(String fileName, Class> clazz)
public static String readFile(String fileName, Class<?> clazz)
//package com.java2s; //License from project: BSD License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static String readFile(String fileName, Class<?> clazz) { StringBuilder sb = new StringBuilder(); BufferedReader br = null; try {// w w w . j a va2 s . c o m br = new BufferedReader(new InputStreamReader(clazz.getResourceAsStream(fileName))); String line; while ((line = br.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null) { br.close(); } } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } }