Resource implementation for java.io.File and
java.nio.file.Path handles with a file system target.
Supports resolution as a File and also as a URL.
Implements the extended WritableResource interface.Note
As of Spring Framework 5.0, this Resource implementation uses
NIO.2 API for read/write interactions. As of 5.1, it may be constructed with a
java. handle in which case it will perform all file system
interactions via NIO.2, only resorting to File on getFile().
FileSystemResource(String), FileSystemResource(File), FileSystemResource(Path), java.io.File , java.nio.file.Files
| Modifier and Type | Field and Description |
|---|---|
| private final File | |
| private final Path | |
| private final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | FileSystemResource(Path
a Path handle to a file filePath)Create a new |
| public | FileSystemResource(FileSystem
the FileSystem to locate the path within fileSystem, String a file path path)Create a new |
| Modifier and Type | Method and Description |
|---|---|
| public long | contentLength()
Overrides org. Implements org. This implementation returns the underlying File/Path length. |
| public Resource | createRelative(String
the relative path (relative to this resource) relativePath)Overrides org. Implements org. This implementation creates a FileSystemResource, applying the given path relative to the path of the underlying file of this resource descriptor. |
| public boolean | equals(Object
the reference object with which to compare. other)Overrides org. This implementation compares the underlying file paths. |
| public boolean | exists()
Overrides org. Implements org. This implementation returns whether the underlying file exists. |
| public byte[] | getContentAsByteArray()
Overrides default org. Return the contents of this resource as a byte array. |
| public String | getContentAsString(Charset
the charset to use for decoding charset)Overrides default org. Return the contents of this resource as a string, using the specified charset. |
| public String | getDescription()
Implements org. This implementation returns a description that includes the absolute path of the file. |
| public File | getFile()
Overrides org. Implements org. This implementation returns the underlying File reference. |
| public String | getFilename()
Overrides org. Implements org. This implementation returns the name of the file. |
| public InputStream | getInputStream()
Implements org. This implementation opens an NIO file stream for the underlying file. |
| public OutputStream | getOutputStream()
Implements org. This implementation opens a FileOutputStream for the underlying file. |
| public final String | |
| public URI | getURI()
Overrides org. Implements org. This implementation returns a URI for the underlying file. |
| public URL | getURL()
Overrides org. Implements org. This implementation returns a URL for the underlying file. |
| public int | hashCode()
Overrides org. This implementation returns the hash code of the underlying file path. |
| public boolean | isFile()
Overrides org. Overrides default org. This implementation always indicates a file. |
| public boolean | isReadable()
Overrides org. Overrides default org. This implementation checks whether the underlying file is marked as readable (and corresponds to an actual file with content, not to a directory). |
| public boolean | isWritable()
Overrides default org. This implementation checks whether the underlying file is marked as writable (and corresponds to an actual file with content, not to a directory). |
| public long | lastModified()
Overrides org. Implements org. This implementation returns the underlying File/Path last-modified time. |
| public ReadableByteChannel | readableChannel()
Overrides org. Overrides default org. This implementation opens a FileChannel for the underlying file. |
| public WritableByteChannel | writableChannel()
Overrides default org. This implementation opens a FileChannel for the underlying file. |
| file | back to summary |
|---|---|
| private final File file
| |
| filePath | back to summary |
|---|---|
| private final Path filePath | |
| path | back to summary |
|---|---|
| private final String path | |
| FileSystemResource | back to summary |
|---|---|
| public FileSystemResource(String path) Create a new Note When building relative resources via
| |
| FileSystemResource | back to summary |
|---|---|
| public FileSystemResource(File file) Create a new Note When building relative resources via
| |
| FileSystemResource | back to summary |
|---|---|
| public FileSystemResource(Path filePath) Create a new In contrast to Note When building relative resources via
| |
| FileSystemResource | back to summary |
|---|---|
| public FileSystemResource(FileSystem fileSystem, String path) Create a new This is an alternative to
| |
| contentLength | back to summary |
|---|---|
| public long contentLength() throws IOException Overrides org. Implements org. This implementation returns the underlying File/Path length.
| |
| createRelative | back to summary |
|---|---|
| public Resource createRelative(String relativePath) Overrides org. Implements org. This implementation creates a FileSystemResource, applying the given path relative to the path of the underlying file of this resource descriptor.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides org. This implementation compares the underlying file paths.
| |
| exists | back to summary |
|---|---|
| public boolean exists() Overrides org. Implements org. This implementation returns whether the underlying file exists.
| |
| getContentAsByteArray | back to summary |
|---|---|
| public byte[] getContentAsByteArray() throws IOException Overrides default org. Doc from org. Return the contents of this resource as a byte array.
| |
| getContentAsString | back to summary |
|---|---|
| public String getContentAsString(Charset charset) throws IOException Overrides default org. Doc from org. Return the contents of this resource as a string, using the specified charset.
| |
| getDescription | back to summary |
|---|---|
| public String getDescription() Implements org. This implementation returns a description that includes the absolute path of the file.
| |
| getFile | back to summary |
|---|---|
| public File getFile() Overrides org. Implements org. This implementation returns the underlying File reference.
| |
| getFilename | back to summary |
|---|---|
| public String getFilename() Overrides org. Implements org. This implementation returns the name of the file.
| |
| getInputStream | back to summary |
|---|---|
| public InputStream getInputStream() throws IOException Implements org. This implementation opens an NIO file stream for the underlying file.
| |
| getOutputStream | back to summary |
|---|---|
| public OutputStream getOutputStream() throws IOException Implements org. This implementation opens a FileOutputStream for the underlying file.
| |
| getPath | back to summary |
|---|---|
| public final String getPath() Return the file path for this resource. | |
| getURI | back to summary |
|---|---|
| public URI getURI() throws IOException Overrides org. Implements org. This implementation returns a URI for the underlying file.
| |
| getURL | back to summary |
|---|---|
| public URL getURL() throws IOException Overrides org. Implements org. This implementation returns a URL for the underlying file.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides org. This implementation returns the hash code of the underlying file path.
| |
| isFile | back to summary |
|---|---|
| public boolean isFile() Overrides org. Overrides default org. This implementation always indicates a file.
| |
| isReadable | back to summary |
|---|---|
| public boolean isReadable() Overrides org. Overrides default org. This implementation checks whether the underlying file is marked as readable (and corresponds to an actual file with content, not to a directory). | |
| isWritable | back to summary |
|---|---|
| public boolean isWritable() Overrides default org. This implementation checks whether the underlying file is marked as writable (and corresponds to an actual file with content, not to a directory). | |
| lastModified | back to summary |
|---|---|
| public long lastModified() throws IOException Overrides org. Implements org. This implementation returns the underlying File/Path last-modified time.
| |
| readableChannel | back to summary |
|---|---|
| public ReadableByteChannel readableChannel() throws IOException Overrides org. Overrides default org. This implementation opens a FileChannel for the underlying file.
| |
| writableChannel | back to summary |
|---|---|
| public WritableByteChannel writableChannel() throws IOException Overrides default org. This implementation opens a FileChannel for the underlying file.
| |