org.springframework.core.io
Class ClassPathResource

org.springframework.core.io.AbstractResource
  |
  +--org.springframework.core.io.ClassPathResource

public class ClassPathResource
extends AbstractResource

Resource implementation for classpath resources. Uses either the Thread context class loader or a given Class for loading resources.

Author:
Juergen Hoeller
Since: 28.12.2003
See Also: java.lang.Thread.getContextClassLoader(), java.lang.ClassLoader.getResourceAsStream(java.lang.String), java.lang.Class.getResourceAsStream(java.lang.String)

Constructor Summary
ClassPathResource(String path)
          Create a new ClassPathResource for ClassLoader usage.
ClassPathResource(String path, Class clazz)
          Create a new ClassPathResource for Class usage.

Method Summary
 StringgetDescription()
           
 InputStreamgetInputStream()
           

Methods inherited from class org.springframework.core.io.AbstractResource
equals, exists, getFile, hashCode, isOpen, toString

Constructor Detail

ClassPathResource

public ClassPathResource(String path)
Create a new ClassPathResource for ClassLoader usage. A leading slash will be removed, as the ClassLoader resource access methods will not accept it.
Parameters:
path - the absolute path within the classpath
See Also:
java.lang.ClassLoader.getResourceAsStream(java.lang.String)

ClassPathResource

public ClassPathResource(String path, Class clazz)
Create a new ClassPathResource for Class usage. The path can be relative to the given class, or absolute within the classpath via a leading slash.
Parameters:
path - relative or absolute path within the classpath
clazz - the class to load resources with
See Also:
java.lang.Class.getResourceAsStream(java.lang.String)
Method Detail

getDescription

public String getDescription()

getInputStream

public InputStream getInputStream()
throws java.io.IOException

Association Links

to Class java.lang.String

to Class java.lang.Class