| 构造器和说明 |
|---|
ClassPathResource(String path)
Create a new
ClassPathResource for ClassLoader usage. |
ClassPathResource(String path,
Class<?> clazz)
Create a new
ClassPathResource for Class usage. |
ClassPathResource(String path,
ClassLoader classLoader)
Create a new
ClassPathResource for ClassLoader usage. |
| 限定符和类型 | 方法和说明 |
|---|---|
long |
contentLength()
Determine the content length for this resource.
|
boolean |
equals(Object obj) |
boolean |
exists()
Determine whether this resource actually exists in physical form.
|
String |
getAbsolutePath() |
ClassLoader |
getClassLoader() |
InputStream |
getInputStream()
Return an
InputStream for the content of an underlying resource. |
URL |
getRealResource() |
URL |
getUrl()
This implementation returns a URL for the underlying class path resource,
if available.
|
URL |
getUrlOrNull() |
int |
hashCode() |
protected URL |
resolveURL() |
String |
toString() |
getLocation, getPath, getPrefix, setLocation, setLocationisReadable, readableChannelpublic 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)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)public String getAbsolutePath()
public URL getRealResource()
public URL getUrl() throws IOException
public boolean exists()
ResourceThis method performs a definitive existence check, whereas the
existence of a Resource handle only guarantees a valid
descriptor handle.
public long contentLength()
Resourcepublic final ClassLoader getClassLoader()
protected URL resolveURL()
public InputStream getInputStream() throws IOException
ResourceInputStream for the content of an underlying resource.
It is expected that each call creates a fresh stream.
This requirement is particularly important when you consider an API such
as JavaMail, which needs to be able to read the stream multiple times when
creating mail attachments. For such a use case, it is required
that each getInputStream() call returns a fresh stream.
null)FileNotFoundException - if the underlying resource doesn't existIOException - if the content stream could not be openedpublic String toString()
toString 在类中 AbstractLocatableResource<URL>public URL getUrlOrNull()
Copyright © 2021. All rights reserved.