public final class Resources extends Object
Modifier and Type | Method and Description |
---|---|
static Class<?> |
classForName(String className)
Loads a class
|
static Charset |
getCharset() |
static ClassLoader |
getDefaultClassLoader()
Returns the default classloader (may be null).
|
static File |
getResourceAsFile(ClassLoader loader,
String resource)
Returns a resource on the classpath as a File object
|
static File |
getResourceAsFile(String resource)
Returns a resource on the classpath as a File object
|
static Properties |
getResourceAsProperties(ClassLoader loader,
String resource)
Returns a resource on the classpath as a Properties object
|
static Properties |
getResourceAsProperties(String resource)
Returns a resource on the classpath as a Properties object
|
static Reader |
getResourceAsReader(ClassLoader loader,
String resource)
Returns a resource on the classpath as a Reader object
|
static Reader |
getResourceAsReader(String resource)
Returns a resource on the classpath as a Reader object
|
static InputStream |
getResourceAsStream(ClassLoader loader,
String resource)
Returns a resource on the classpath as a Stream object
|
static InputStream |
getResourceAsStream(String resource)
Returns a resource on the classpath as a Stream object
|
static URL |
getResourceURL(ClassLoader loader,
String resource)
Returns the URL of the resource on the classpath
|
static URL |
getResourceURL(String resource)
Returns the URL of the resource on the classpath
|
static Properties |
getUrlAsProperties(String urlString)
Gets a URL as a Properties object
|
static Reader |
getUrlAsReader(String urlString)
Gets a URL as a Reader
|
static InputStream |
getUrlAsStream(String urlString)
Gets a URL as an input stream
|
static Object |
instantiate(Class<?> clazz)
Creates an instance of a class
|
static Object |
instantiate(String className)
Creates an instance of a class
|
static void |
setCharset(Charset charset)
Use this method to set the Charset to be used when calling the
getResourceAsReader methods.
|
static void |
setDefaultClassLoader(ClassLoader defaultClassLoader)
Sets the default classloader
|
public static ClassLoader getDefaultClassLoader()
public static void setDefaultClassLoader(ClassLoader defaultClassLoader)
defaultClassLoader
- - the new default ClassLoaderpublic static URL getResourceURL(String resource) throws IOException
resource
- The resource to findIOException
- If the resource cannot be found or readpublic static URL getResourceURL(ClassLoader loader, String resource) throws IOException
loader
- The classloader used to load the resourceresource
- The resource to findIOException
- If the resource cannot be found or readpublic static InputStream getResourceAsStream(String resource) throws IOException
resource
- The resource to findIOException
- If the resource cannot be found or readpublic static InputStream getResourceAsStream(ClassLoader loader, String resource) throws IOException
loader
- The classloader used to load the resourceresource
- The resource to findIOException
- If the resource cannot be found or readpublic static Properties getResourceAsProperties(String resource) throws IOException
resource
- The resource to findIOException
- If the resource cannot be found or readpublic static Properties getResourceAsProperties(ClassLoader loader, String resource) throws IOException
loader
- The classloader used to load the resourceresource
- The resource to findIOException
- If the resource cannot be found or readpublic static Reader getResourceAsReader(String resource) throws IOException
resource
- The resource to findIOException
- If the resource cannot be found or readpublic static Reader getResourceAsReader(ClassLoader loader, String resource) throws IOException
loader
- The classloader used to load the resourceresource
- The resource to findIOException
- If the resource cannot be found or readpublic static File getResourceAsFile(String resource) throws IOException
resource
- The resource to findIOException
- If the resource cannot be found or readpublic static File getResourceAsFile(ClassLoader loader, String resource) throws IOException
loader
- - the classloader used to load the resourceresource
- - the resource to findIOException
- If the resource cannot be found or readpublic static InputStream getUrlAsStream(String urlString) throws IOException
urlString
- - the URL to getIOException
- If the resource cannot be found or readpublic static Reader getUrlAsReader(String urlString) throws IOException
urlString
- - the URL to getIOException
- If the resource cannot be found or readpublic static Properties getUrlAsProperties(String urlString) throws IOException
urlString
- - the URL to getIOException
- If the resource cannot be found or readpublic static Class<?> classForName(String className) throws ClassNotFoundException
className
- - the class to loadClassNotFoundException
- If the class cannot be found (duh!)public static Object instantiate(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException
className
- - the class to createClassNotFoundException
- If the class cannot be found (duh!)InstantiationException
- If the class cannot be instantiaedIllegalAccessException
- If the class is not public, or other access problems arisepublic static Object instantiate(Class<?> clazz) throws InstantiationException, IllegalAccessException
clazz
- - the class to createInstantiationException
- If the class cannot be instantiaedIllegalAccessException
- If the class is not public, or other access problems arisepublic static Charset getCharset()
public static void setCharset(Charset charset)
charset
- Copyright © 2006–2018 TinyGroup. All rights reserved.