- java提供的资源访问类(URL,File)不能很好的满足各种底层资源访问需求。Spring设计了一个Resource接口为应用提供了更强的底层资源访问能力,此接口拥有对应不同资源类型的实现类。
1、Resource接口主要方法
public interface Resource extends InputStreamSource {
boolean exists();
boolean isReadable();
boolean isOpen();
URL getURL() throws IOException;
URI getURI() throws IOException;
File getFile() throws IOException;
long contentLength() throws IOException;
long lastModified() throws IOException;
Resource createRelative(String var1) throws IOException;
String getFilename();
String getDescription();
}
- 1、boolean exists():资源是否存在
- 2、boolean isOpen():资源是否打开
- 3、URL getUR() throws IOException:如果底层资源表示成URL,则该方法返回对应的URL对象
- 4、File getFile() throws IOException:如果底层资源对应一个文件,则该方法返回对应的File对象
- 5、InputStream getInputStream() throws:返回资源对应的输入流
2、Resource体系
Resource
-->WritableResource
-->AbstractResource
------>ByteArrayResource<