类 FileSystemResource

    • 字段概要

      字段 
      修饰符和类型 字段 说明
      private java.io.File file  
      private java.nio.file.Path filePath  
      private java.lang.String path  
    • 构造器概要

      构造器 
      构造器 说明
      FileSystemResource​(java.io.File file)
      Create a new FileSystemResource from a File handle.
      FileSystemResource​(java.lang.String path)
      Create a new FileSystemResource from a file path.
      FileSystemResource​(java.nio.file.FileSystem fileSystem, java.lang.String path)
      Create a new FileSystemResource from a FileSystem handle, locating the specified path.
      FileSystemResource​(java.nio.file.Path filePath)
      Create a new FileSystemResource from a Path handle, performing all file system interactions via NIO.2 instead of File.
    • 方法概要

      所有方法 实例方法 具体方法 
      修饰符和类型 方法 说明
      long contentLength()
      This implementation returns the underlying File/Path length.
      Resource createRelative​(java.lang.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​(java.lang.Object other)
      This implementation compares the underlying File references.
      boolean exists()
      This implementation returns whether the underlying file exists.
      java.lang.String getDescription()
      This implementation returns a description that includes the absolute path of the file.
      java.io.File getFile()
      This implementation returns the underlying File reference.
      java.lang.String getFilename()
      This implementation returns the name of the file.
      java.io.InputStream getInputStream()
      This implementation opens a NIO file stream for the underlying file.
      java.io.OutputStream getOutputStream()
      This implementation opens a FileOutputStream for the underlying file.
      java.lang.String getPath()
      Return the file path for this resource.
      java.net.URI getUri()
      This implementation returns a URI for the underlying file.
      java.net.URL getUrl()
      This implementation returns a URL for the underlying file.
      int hashCode()
      This implementation returns the hash code of the underlying File reference.
      boolean isFile()
      This implementation always indicates a file.
      boolean isReadable()
      This implementation checks whether the underlying file is marked as readable (and corresponds to an actual file with content, not to a directory).
      boolean isWritable()
      This implementation checks whether the underlying file is marked as writable (and corresponds to an actual file with content, not to a directory).
      long lastModified()
      This implementation returns the underlying File/Path last-modified time.
      java.nio.channels.ReadableByteChannel readableChannel()
      This implementation opens a FileChannel for the underlying file.
      java.nio.channels.WritableByteChannel writableChannel()
      This implementation opens a FileChannel for the underlying file.
      • 从类继承的方法 java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • 从接口继承的方法 com.alibaba.nacos.common.packagescan.resource.Resource

        isOpen
    • 字段详细资料

      • path

        private final java.lang.String path
      • file

        private final java.io.File file
      • filePath

        private final java.nio.file.Path filePath
    • 构造器详细资料

      • FileSystemResource

        public FileSystemResource​(java.lang.String path)
        Create a new FileSystemResource from a file path.

        Note: When building relative resources via createRelative(java.lang.String), it makes a difference whether the specified resource base path here ends with a slash or not. In the case of "C:/dir1/", relative paths will be built underneath that root: e.g. relative path "dir2" → "C:/dir1/dir2". In the case of "C:/dir1", relative paths will apply at the same directory level: relative path "dir2" → "C:/dir2".

        参数:
        path - a file path
        另请参阅:
        FileSystemResource(Path)
      • FileSystemResource

        public FileSystemResource​(java.io.File file)
        Create a new FileSystemResource from a File handle.

        Note: When building relative resources via createRelative(java.lang.String), the relative path will apply at the same directory level: e.g. new File("C:/dir1"), relative path "dir2" → "C:/dir2"! If you prefer to have relative paths built underneath the given root directory, use the constructor with a file path to append a trailing slash to the root path: "C:/dir1/", which indicates this directory as root for all relative paths.

        参数:
        file - a File handle
        另请参阅:
        FileSystemResource(Path), getFile()
      • FileSystemResource

        public FileSystemResource​(java.nio.file.Path filePath)
        Create a new FileSystemResource from a Path handle, performing all file system interactions via NIO.2 instead of File.

        In contrast to PathResource, this variant strictly follows the general FileSystemResource conventions, in particular in terms of path cleaning and createRelative(String) handling.

        Note: When building relative resources via createRelative(java.lang.String), the relative path will apply at the same directory level: e.g. Paths.get("C:/dir1"), relative path "dir2" → "C:/dir2"! If you prefer to have relative paths built underneath the given root directory, use the constructor with a file path to append a trailing slash to the root path: "C:/dir1/", which indicates this directory as root for all relative paths. Alternatively, consider using PathResource(Path) for java.nio.path.Path resolution in createRelative, always nesting relative paths.

        参数:
        filePath - a Path handle to a file
        从以下版本开始:
        5.1
        另请参阅:
        FileSystemResource(File)
      • FileSystemResource

        public FileSystemResource​(java.nio.file.FileSystem fileSystem,
                                  java.lang.String path)
        Create a new FileSystemResource from a FileSystem handle, locating the specified path.

        This is an alternative to FileSystemResource(String), performing all file system interactions via NIO.2 instead of File.

        参数:
        fileSystem - the FileSystem to locate the path within
        path - a file path
        从以下版本开始:
        5.1.1
        另请参阅:
        FileSystemResource(File)
    • 方法详细资料

      • getPath

        public final java.lang.String getPath()
        Return the file path for this resource.
      • exists

        public boolean exists()
        This implementation returns whether the underlying file exists.
        指定者:
        exists 在接口中 Resource
        覆盖:
        exists 在类中 AbstractResource
        另请参阅:
        File.exists()
      • isReadable

        public boolean isReadable()
        This implementation checks whether the underlying file is marked as readable (and corresponds to an actual file with content, not to a directory).
        指定者:
        isReadable 在接口中 Resource
        覆盖:
        isReadable 在类中 AbstractResource
        另请参阅:
        File.canRead(), File.isDirectory()
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        This implementation opens a NIO file stream for the underlying file.
        指定者:
        getInputStream 在接口中 InputStreamSource
        返回:
        the input stream for the underlying resource (must not be null)
        抛出:
        java.io.FileNotFoundException - if the underlying resource does not exist
        java.io.IOException - if the content stream could not be opened
        另请参阅:
        FileInputStream
      • isWritable

        public boolean isWritable()
        This implementation checks whether the underlying file is marked as writable (and corresponds to an actual file with content, not to a directory).
        指定者:
        isWritable 在接口中 WritableResource
        另请参阅:
        File.canWrite(), File.isDirectory()
      • getOutputStream

        public java.io.OutputStream getOutputStream()
                                             throws java.io.IOException
        This implementation opens a FileOutputStream for the underlying file.
        指定者:
        getOutputStream 在接口中 WritableResource
        抛出:
        java.io.IOException - if the stream could not be opened
        另请参阅:
        FileOutputStream
      • getUrl

        public java.net.URL getUrl()
                            throws java.io.IOException
        This implementation returns a URL for the underlying file.
        指定者:
        getUrl 在接口中 Resource
        覆盖:
        getUrl 在类中 AbstractResource
        抛出:
        java.io.IOException - if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor
        另请参阅:
        File.toURI()
      • getUri

        public java.net.URI getUri()
                            throws java.io.IOException
        This implementation returns a URI for the underlying file.
        指定者:
        getUri 在接口中 Resource
        覆盖:
        getUri 在类中 AbstractResource
        抛出:
        java.io.IOException - if the resource cannot be resolved as URI, i.e. if the resource is not available as descriptor
        另请参阅:
        File.toURI()
      • readableChannel

        public java.nio.channels.ReadableByteChannel readableChannel()
                                                              throws java.io.IOException
        This implementation opens a FileChannel for the underlying file.
        指定者:
        readableChannel 在接口中 Resource
        覆盖:
        readableChannel 在类中 AbstractResource
        返回:
        the byte channel for the underlying resource (must not be null)
        抛出:
        java.io.FileNotFoundException - if the underlying resource doesn't exist
        java.io.IOException - if the content channel could not be opened
        另请参阅:
        FileChannel
      • writableChannel

        public java.nio.channels.WritableByteChannel writableChannel()
                                                              throws java.io.IOException
        This implementation opens a FileChannel for the underlying file.
        指定者:
        writableChannel 在接口中 WritableResource
        返回:
        the byte channel for the underlying resource (must not be null)
        抛出:
        java.io.FileNotFoundException - if the underlying resource doesn't exist
        java.io.IOException - if the content channel could not be opened
        另请参阅:
        FileChannel
      • getDescription

        public java.lang.String getDescription()
        This implementation returns a description that includes the absolute path of the file.
        指定者:
        getDescription 在接口中 Resource
        另请参阅:
        File.getAbsolutePath()