Java Resource Load getResourceAsBytes(Class testClass, String resourceName)

Here you can find the source of getResourceAsBytes(Class testClass, String resourceName)

Description

Load a file into memory as a byte array.

License

Open Source License

Parameter

Parameter Description
testClass the class to use as the reference class for loading the resource
resourceName name of the resource, If the name starts with / then the resources is relative to the root of the classpath otherwise the resource is relative to the package of the testclass

Declaration

public static byte[] getResourceAsBytes(Class<?> testClass, String resourceName) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import com.google.common.io.Resources;
import java.io.IOException;

public class Main {
    /**//from  w w w  . jav  a 2  s.  c  om
     * Load a file into memory as a byte array.
     *
     * @param testClass the class to use as the reference class for loading the resource
     * @param resourceName name of the resource, If the name starts with / then the resources is relative to the root of the classpath
     *                     otherwise the resource is relative to the package of the testclass
     */
    public static byte[] getResourceAsBytes(Class<?> testClass, String resourceName) throws IOException {
        return Resources.toByteArray(testClass.getResource(resourceName));
    }
}

Related

  1. getResourceAbsolutePath(String pluginId, String... path)
  2. getResourceAsBufferedReader(Class clazz, String resourceName)
  3. getResourceAsByteArray(Object context, String resourceName)
  4. getResourceAsByteArray(String url)
  5. getResourceAsBytes(Class cl, String resname)
  6. getResourceAsBytes(ClassLoader classLoader, String resourcePath)
  7. getResourceAsBytes(String path, ClassLoader loader)
  8. getResourceAsBytes(String url)
  9. getResourceAsFile(String path)