Here you can find the source of getResourceAsString(Class> clazz, String name)
public static String getResourceAsString(Class<?> clazz, String name)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 Oobium, Inc./*from w w w . j av a 2s .com*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Jeremy Dowdall <jeremy@oobium.com> - initial API and implementation ******************************************************************************/ import java.io.IOException; import java.io.InputStream; public class Main { public static String getResourceAsString(Class<?> clazz, String name) { return getString(clazz.getResourceAsStream(name)); } public static String getString(InputStream in) { if (in != null) { try { StringBuilder sb = new StringBuilder(); int c; while ((c = in.read()) != -1) { sb.append((char) c); } return sb.toString(); } catch (IOException e) { // discard } } return null; } }