Package org.aoju.bus.core.io.resource
Class ClassPathResource
java.lang.Object
org.aoju.bus.core.io.resource.UriResource
org.aoju.bus.core.io.resource.ClassPathResource
- All Implemented Interfaces:
Resource
ClassPath单一资源访问类 传入路径path必须为相对路径,如果传入绝对路径,Linux路径会去掉开头的“/”,而Windows路径会直接报错 传入的path所指向的资源必须存在,否则报错
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
Fields inherited from class org.aoju.bus.core.io.resource.UriResource
name, url -
Constructor Summary
ConstructorsConstructorDescriptionClassPathResource(String path) 构造ClassPathResource(String path, Class<?> clazz) 构造ClassPathResource(String path, ClassLoader classLoader) 构造ClassPathResource(String pathBaseClassLoader, ClassLoader classLoader, Class<?> clazz) 构造 -
Method Summary
Modifier and TypeMethodDescriptionfinal String获得绝对路径Path 对于不存在的资源,返回拼接后的绝对路径final ClassLoader获得ClassLoaderfinal StringgetPath()获得PathtoString()返回路径Methods inherited from class org.aoju.bus.core.io.resource.UriResource
getFile, getName, getStream, getUrl, isModifiedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.aoju.bus.core.io.resource.Resource
getReader, readBytes, readString, writeTo
-
Constructor Details
-
ClassPathResource
-
ClassPathResource
构造- Parameters:
path- 相对于ClassPath的路径classLoader-ClassLoader
-
ClassPathResource
-
ClassPathResource
构造- Parameters:
pathBaseClassLoader- 相对路径classLoader-ClassLoaderclazz-Class用于定位路径
-
-
Method Details
-
getPath
-
getAbsolutePath
-
getClassLoader
-
toString
Description copied from class:UriResource返回路径- Overrides:
toStringin classUriResource- Returns:
- 返回URL路径
-