Here you can find the source of getResource(Class clazz, String fileName)
public static String getResource(Class clazz, String fileName)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static String getResource(Class clazz, String fileName) { try {/* w ww .ja va 2 s . c o m*/ File file = new File(clazz.getResource(fileName).getFile()); BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8")); StringBuilder builder = new StringBuilder(); String str; while ((str = in.readLine()) != null) { builder.append(str); } in.close(); return builder.toString(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } }