Class FileSystemResource

java.lang.Object
org.springframework.core.io.AbstractResource
org.springframework.core.io.FileSystemResource
All Implemented Interfaces:
InputStreamSource, Resource, WritableResource

public class FileSystemResource extends AbstractResource implements WritableResource
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 Path handle in which case it will perform all file system interactions via NIO.2, only resorting to File on getFile().

Since:
28.12.2003
Author:
Juergen Hoeller
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new FileSystemResource from a File handle.
    Create a new FileSystemResource from a file path.
    Create a new FileSystemResource from a FileSystem handle, locating the specified path.
    Create a new FileSystemResource from a Path handle, performing all file system interactions via NIO.2 instead of File.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    This implementation returns the underlying File/Path length.
    createRelative(String relativePath)
    This implementation creates a FileSystemResource, applying the given path relative to the path of the underlying file of this resource descriptor.
    boolean
    equals(Object other)
    This implementation compares the underlying File references.
    boolean
    This implementation returns whether the underlying file exists.
    This implementation returns a description that includes the absolute path of the file.
    This implementation returns the underlying File reference.
    This implementation returns the name of the file.
    This implementation opens a NIO file stream for the underlying file.
    This implementation opens a FileOutputStream for the underlying file.
    final String
    Return the file path for this resource.
    This implementation returns a URI for the underlying file.
    This implementation returns a URL for the underlying file.
    int
    This implementation returns the hash code of the underlying File reference.
    boolean
    This implementation always indicates a file.
    boolean
    This implementation checks whether the underlying file is marked as readable (and corresponds to an actual file with content, not to a directory).
    boolean
    This implementation checks whether the underlying file is marked as writable (and corresponds to an actual file with content, not to a directory).
    long
    This implementation returns the underlying File/Path last-modified time.
    This implementation opens a FileChannel for the underlying file.
    This implementation opens a FileChannel for the underlying file.

    Methods inherited from class org.springframework.core.io.AbstractResource

    getFileForLastModifiedCheck, isOpen, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.springframework.core.io.Resource

    isOpen