Here you can find the source of readResourceUtf8(Class> contextClass, String filename)
public static String readResourceUtf8(Class<?> contextClass, String filename)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import static com.google.common.io.Resources.getResource; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.io.Resources; import java.io.IOException; import java.net.URL; public class Main { /** Loads a file as a string, assuming UTF-8 encoding. */ public static String readResourceUtf8(String filename) { return resourceToString(getResource(filename)); }/*from w ww .j a v a2 s . c o m*/ /** Loads a file (specified relative to the contextClass) as a string, assuming UTF-8 encoding. */ public static String readResourceUtf8(Class<?> contextClass, String filename) { return resourceToString(getResource(contextClass, filename)); } private static String resourceToString(URL url) { try { return Resources.toString(url, UTF_8); } catch (IOException e) { throw new IllegalArgumentException("Failed to load resource: " + url, e); } } }