public class ClassPathResource extends AbstractFileResolvingResource
Resource implementation for class path resources. Uses either a
 given ClassLoader or a given Class for loading resources.
 Supports resolution as java.io.File if the class path
 resource resides in the file system, but not for resources in a JAR.
 Always supports resolution as URL.
ClassLoader.getResourceAsStream(String), 
Class.getResourceAsStream(String)| Modifier | Constructor and Description | 
|---|---|
|   | ClassPathResource(String path)Create a new  ClassPathResourceforClassLoaderusage. | 
|   | ClassPathResource(String path,
                 Class<?> clazz)Create a new  ClassPathResourceforClassusage. | 
|   | ClassPathResource(String path,
                 ClassLoader classLoader)Create a new  ClassPathResourceforClassLoaderusage. | 
| protected  | ClassPathResource(String path,
                 ClassLoader classLoader,
                 Class<?> clazz)Deprecated. 
 as of 4.3.13, in favor of selective use of
  ClassPathResource(String, ClassLoader)vsClassPathResource(String, Class) | 
| Modifier and Type | Method and Description | 
|---|---|
| Resource | createRelative(String relativePath)This implementation creates a ClassPathResource, applying the given path
 relative to the path of the underlying resource of this descriptor. | 
| boolean | equals(Object other)This implementation compares the underlying class path locations. | 
| boolean | exists()This implementation checks for the resolution of a resource URL. | 
| ClassLoader | getClassLoader()Return the ClassLoader that this resource will be obtained from. | 
| String | getDescription()This implementation returns a description that includes the class path location. | 
| String | getFilename()This implementation returns the name of the file that this class path
 resource refers to. | 
| InputStream | getInputStream()This implementation opens an InputStream for the given class path resource. | 
| String | getPath()Return the path for this resource (as resource path within the class path). | 
| URL | getURL()This implementation returns a URL for the underlying class path resource,
 if available. | 
| int | hashCode()This implementation returns the hash code of the underlying
 class path location. | 
| protected URL | resolveURL()Resolves a URL for the underlying class path resource. | 
contentLength, customizeConnection, customizeConnection, getFile, getFile, getFileForLastModifiedCheck, isFile, isFile, isReadable, lastModified, readableChannelgetURI, isOpen, toStringpublic ClassPathResource(String path)
ClassPathResource for ClassLoader usage.
 A leading slash will be removed, as the ClassLoader resource access
 methods will not accept it.
 The thread context class loader will be used for loading the resource.
path - the absolute path within the class pathClassLoader.getResourceAsStream(String), 
ClassUtils.getDefaultClassLoader()public ClassPathResource(String path, @Nullable ClassLoader classLoader)
ClassPathResource for ClassLoader usage.
 A leading slash will be removed, as the ClassLoader resource access
 methods will not accept it.path - the absolute path within the classpathclassLoader - the class loader to load the resource with,
 or null for the thread context class loaderClassLoader.getResourceAsStream(String)public ClassPathResource(String path, @Nullable Class<?> clazz)
ClassPathResource for Class usage.
 The path can be relative to the given class, or absolute within
 the classpath via a leading slash.path - relative or absolute path within the class pathclazz - the class to load resources withClass.getResourceAsStream(java.lang.String)@Deprecated protected ClassPathResource(String path, @Nullable ClassLoader classLoader, @Nullable Class<?> clazz)
ClassPathResource(String, ClassLoader) vs ClassPathResource(String, Class)ClassPathResource with optional ClassLoader
 and Class. Only for internal usage.path - relative or absolute path within the classpathclassLoader - the class loader to load the resource with, if anyclazz - the class to load resources with, if anypublic final String getPath()
@Nullable public final ClassLoader getClassLoader()
public boolean exists()
exists in interface Resourceexists in class AbstractFileResolvingResourceClassLoader.getResource(String), 
Class.getResource(String)@Nullable protected URL resolveURL()
null if not resolvablepublic InputStream getInputStream() throws IOException
null)FileNotFoundException - if the underlying resource doesn't existIOException - if the content stream could not be openedClassLoader.getResourceAsStream(String), 
Class.getResourceAsStream(String)public URL getURL() throws IOException
getURL in interface ResourcegetURL in class AbstractResourceIOException - if the resource cannot be resolved as URL,
 i.e. if the resource is not available as descriptorClassLoader.getResource(String), 
Class.getResource(String)public Resource createRelative(String relativePath)
createRelative in interface ResourcecreateRelative in class AbstractResourcerelativePath - the relative path (relative to this resource)StringUtils.applyRelativePath(String, String)@Nullable public String getFilename()
getFilename in interface ResourcegetFilename in class AbstractResourceStringUtils.getFilename(String)public String getDescription()
Object.toString()public boolean equals(Object other)
equals in class AbstractResourceResource.getDescription()public int hashCode()
hashCode in class AbstractResourceResource.getDescription()