Java Utililty Methods Resource Get

List of utility methods to do Resource Get

Description

The list of methods to do Resource Get are organized into topic(s).

Method

ListgetResourcesFromDirectory(File resource, Pattern pattern)
get Resources From Directory
ArrayList<URL> urls = new ArrayList<>();
final File[] fileList = resource.listFiles();
if (fileList == null)
    return urls;
for (final File file : fileList) {
    if (file.isDirectory()) {
        urls.addAll(getResourcesFromDirectory(file, pattern));
    } else {
...
StringgetResourceString(ResourceBundle rb, String key, Object param1)
Get formatted string from resource bundle
String raw = rb.getString(key);
Object params[] = new Object[1];
params[0] = param1;
String formatted = MessageFormat.format(raw, params);
return formatted;
StringgetResourceString(String key)
Returns a string from the resource bundle.
try {
    return resourceBundle.getString(key);
} catch (MissingResourceException e) {
    return key;
} catch (NullPointerException e) {
    return "!" + key + "!";
StringgetResourceString(String key, Object... args)
get Resource String
ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE);
String str = bundle.getString(key);
return MessageFormat.format(str, args);
URLloadResource(Class contextClass, String resourceName)
Returns the url of a resource.
URL url = null;
if (contextClass != null) {
    url = Resources.getResource(contextClass, resourceName);
if (url == null && Thread.currentThread().getContextClassLoader() != null) {
    url = Thread.currentThread().getContextClassLoader().getResource(resourceName);
return url;
...
InputStreamloadResource(final String name)
Load given resource and return as an input stream.
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource(name);
if (url != null) {
    return url.openStream();
return new FileInputStream(name);
byte[]loadResource(final String s)
Method loadResource
final URL url = new URL(s);
final InputStream inputstream = url.openStream();
final byte data[] = readFully(inputstream);
inputstream.close();
return data;
byte[]readResource(String resource, Class c)
_more_
return readResource(resource, c, false);
StringreadToString(final Class nearClass, final String resource)
Returns text content read from the file located near specified class.
try {
    return readToString(nearClass.getResourceAsStream(resource));
} catch (final Throwable e) {
    return null;
StringreadToString(final Class nearClass, final String resource, final String encoding)
Returns content read from the file located near specified class.
try {
    return readToString(nearClass.getResourceAsStream(resource), encoding);
} catch (final Throwable e) {
    return null;