Here you can find the source of getResource(Class clazz, String name, String charset)
public static String getResource(Class clazz, String name, String charset) throws IOException
//package com.java2s; /******************************************************************************* * Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) * Copyright (c) 2011- kotemaru@kotemaru.org ******************************************************************************/ import java.io.*; public class Main { public static String getResource(Class clazz, String name) throws IOException { InputStream in = clazz.getResourceAsStream(name); try {/*w w w. jav a 2 s. c o m*/ return readerToString(new InputStreamReader(in, "UTF-8")); } finally { in.close(); } } public static String getResource(Class clazz, String name, String charset) throws IOException { InputStream in = clazz.getResourceAsStream(name); try { return readerToString(new InputStreamReader(in, charset)); } finally { in.close(); } } public static String readerToString(Reader reader) throws IOException { StringBuffer sbuf = new StringBuffer(); int n = 0; char[] buff = new char[4096]; while ((n = reader.read(buff)) > 0) { sbuf.append(buff, 0, n); } return sbuf.toString(); } }