Here you can find the source of getResourceAsBytes(Class> testClass, String resourceName)
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 |
public static byte[] getResourceAsBytes(Class<?> testClass, String resourceName) throws IOException
//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)); } }