public abstract classFileSystemProviderextendsObject
Files class will typically delegate to an instance of this class. A file system provider is a concrete implementation of this class that implements the abstract methods defined by this class. A provider is identified by aURIscheme. The default provider is identified by the URI scheme "file". It creates theFileSystem that provides access to the file systems accessible to the Java virtual machine. TheFileSystems class defines how file system providers are located and loaded. The default provider is typically a system-default provider but may be overridden if the system propertyjava.nio.file.spi.DefaultFileSystemProvider is set. In that case, the provider has a one argument constructor whose formal parameter type isFileSystemProvider. All other providers have a zero argument constructor that initializes the provider.
A provider is a factory for one or moreFileSystem instances. Each file system is identified by aURI where the URI's scheme matches the provider'sscheme. The default file system, for example, is identified by the URI"file:///". A memory-based file system, for example, may be identified by a URI such as"memory:///?name=logfs". ThenewFileSystem method may be used to create a file system, and thegetFileSystem method may be used to obtain a reference to an existing file system created by the provider. Where a provider is the factory for a single file system then it is provider dependent if the file system is created when the provider is initialized, or later when thenewFileSystem method is invoked. In the case of the default provider, theFileSystem is created when the provider is initialized.
All of the methods in this class are safe for use by multiple concurrent threads.
| Modifier | Constructor | Description |
|---|---|---|
protected | FileSystemProvider() | Initializes a new instance of this class. |
| Modifier and Type | Method | Description |
|---|---|---|
abstract void | checkAccess(Path path,AccessMode... modes) | Checks the existence, and optionally the accessibility, of a file. |
abstract void | copy(Path source,Path target,CopyOption... options) | Copy a file to a target file. |
abstract void | createDirectory(Path dir,FileAttribute<?>... attrs) | Creates a new directory. |
void | createLink(Path link,Path existing) | Creates a new link (directory entry) for an existing file. |
void | createSymbolicLink(Path link,Path target,FileAttribute<?>... attrs) | Creates a symbolic link to a target. |
abstract void | delete(Path path) | Deletes a file. |
boolean | deleteIfExists(Path path) | Deletes a file if it exists. |
abstract <V extendsFileAttributeView> | getFileAttributeView(Path path,Class<V> type,LinkOption... options) | Returns a file attribute view of a given type. |
abstractFileStore | getFileStore(Path path) | Returns the FileStore representing the file store where a file is located. |
abstractFileSystem | getFileSystem(URI uri) | Returns an existing FileSystem created by this provider. |
abstractPath | getPath(URI uri) | Return a Path object by converting the givenURI. |
abstractString | getScheme() | Returns the URI scheme that identifies this provider. |
staticList<FileSystemProvider> | installedProviders() | Returns a list of the installed file system providers. |
abstract boolean | isHidden(Path path) | Tells whether or not a file is consideredhidden. |
abstract boolean | isSameFile(Path path,Path path2) | Tests if two paths locate the same file. |
abstract void | move(Path source,Path target,CopyOption... options) | Move or rename a file to a target file. |
AsynchronousFileChannel | newAsynchronousFileChannel(Path path,Set<? extendsOpenOption> options,ExecutorService executor,FileAttribute<?>... attrs) | Opens or creates a file for reading and/or writing, returning an asynchronous file channel to access the file. |
abstractSeekableByteChannel | newByteChannel(Path path,Set<? extendsOpenOption> options,FileAttribute<?>... attrs) | Opens or creates a file, returning a seekable byte channel to access the file. |
abstractDirectoryStream<Path> | newDirectoryStream(Path dir,DirectoryStream.Filter<? superPath> filter) | Opens a directory, returning a DirectoryStream to iterate over the entries in the directory. |
FileChannel | newFileChannel(Path path,Set<? extendsOpenOption> options,FileAttribute<?>... attrs) | Opens or creates a file for reading and/or writing, returning a file channel to access the file. |
FileSystem | newFileSystem(Path path,Map<String,?> env) | Constructs a new FileSystem to access the contents of a file as a file system. |
abstractFileSystem | newFileSystem(URI uri,Map<String,?> env) | Constructs a new FileSystem object identified by a URI. |
InputStream | newInputStream(Path path,OpenOption... options) | Opens a file, returning an input stream to read from the file. |
OutputStream | newOutputStream(Path path,OpenOption... options) | Opens or creates a file, returning an output stream that may be used to write bytes to the file. |
abstract <A extendsBasicFileAttributes> | readAttributes(Path path,Class<A> type,LinkOption... options) | Reads a file's attributes as a bulk operation. |
abstractMap<String,Object> | readAttributes(Path path,String attributes,LinkOption... options) | Reads a set of file attributes as a bulk operation. |
Path | readSymbolicLink(Path link) | Reads the target of a symbolic link. |
abstract void | setAttribute(Path path,String attribute,Object value,LinkOption... options) | Sets the value of a file attribute. |
protected FileSystemProvider()
During construction a provider may safely access files associated with the default provider but care needs to be taken to avoid circular loading of other installed providers. If circular loading of installed providers is detected then an unspecified error is thrown.
SecurityException - If a security manager has been installed and it deniesRuntimePermission("fileSystemProvider")public static List<FileSystemProvider> installedProviders()
The first invocation of this method causes the default provider to be initialized (if not already initialized) and loads any other installed providers as described by theFileSystems class.
ServiceConfigurationError - When an error occurs while loading a service providerpublic abstract String getScheme()
public abstract FileSystem newFileSystem(URI uri,Map<String,?> env) throwsIOException
FileSystem object identified by a URI. This method is invoked by theFileSystems.newFileSystem(URI,Map) method to open a new file system identified by a URI. Theuri parameter is an absolute, hierarchical URI, with a scheme equal (without regard to case) to the scheme supported by this provider. The exact form of the URI is highly provider dependent. Theenv parameter is a map of provider specific properties to configure the file system.
This method throwsFileSystemAlreadyExistsException if the file system already exists because it was previously created by an invocation of this method. Once a file system isclosed it is provider-dependent if the provider allows a new file system to be created with the same URI as a file system it previously created.
uri - URI referenceenv - A map of provider specific properties to configure the file system; may be emptyIllegalArgumentException - If the pre-conditions for theuri parameter aren't met, or theenv parameter does not contain properties required by the provider, or a property value is invalidIOException - An I/O error occurs creating the file systemSecurityException - If a security manager is installed and it denies an unspecified permission required by the file system provider implementationFileSystemAlreadyExistsException - If the file system has already been createdpublic abstract FileSystem getFileSystem(URI uri)
FileSystem created by this provider. This method returns a reference to aFileSystem that was created by invoking thenewFileSystem(URI,Map) method. File systems created thenewFileSystem(Path,Map) method are not returned by this method. The file system is identified by itsURI. Its exact form is highly provider dependent. In the case of the default provider the URI's path component is"/" and the authority, query and fragment components are undefined (Undefined components are represented bynull).
Once a file system created by this provider isclosed it is provider-dependent if this method returns a reference to the closed file system or throwsFileSystemNotFoundException. If the provider allows a new file system to be created with the same URI as a file system it previously created then this method throws the exception if invoked after the file system is closed (and before a new instance is created by thenewFileSystem method).
If a security manager is installed then a provider implementation may require to check a permission before returning a reference to an existing file system. In the case of thedefault file system, no permission check is required.
uri - URI referenceIllegalArgumentException - If the pre-conditions for theuri parameter aren't metFileSystemNotFoundException - If the file system does not existSecurityException - If a security manager is installed and it denies an unspecified permission.public abstract Path getPath(URI uri)
Path object by converting the givenURI. The resultingPath is associated with aFileSystem that already exists or is constructed automatically. The exact form of the URI is file system provider dependent. In the case of the default provider, the URI scheme is"file" and the given URI has a non-empty path component, and undefined query, and fragment components. The resultingPath is associated with the defaultdefaultFileSystem.
If a security manager is installed then a provider implementation may require to check a permission. In the case of thedefault file system, no permission check is required.
uri - The URI to convertPathIllegalArgumentException - If the URI scheme does not identify this provider or other preconditions on the uri parameter do not holdFileSystemNotFoundException - The file system, identified by the URI, does not exist and cannot be created automaticallySecurityException - If a security manager is installed and it denies an unspecified permission.public FileSystem newFileSystem(Path path,Map<String,?> env) throwsIOException
FileSystem to access the contents of a file as a file system. This method is intended for specialized providers of pseudo file systems where the contents of one or more files is treated as a file system. Theenv parameter is a map of provider specific properties to configure the file system.
If this provider does not support the creation of such file systems or if the provider does not recognize the file type of the given file then it throwsUnsupportedOperationException. The default implementation of this method throwsUnsupportedOperationException.
path - The path to the fileenv - A map of provider specific properties to configure the file system; may be emptyUnsupportedOperationException - If this provider does not support access to the contents as a file system or it does not recognize the file type of the given fileIllegalArgumentException - If theenv parameter does not contain properties required by the provider, or a property value is invalidIOException - If an I/O error occursSecurityException - If a security manager is installed and it denies an unspecified permission.public InputStream newInputStream(Path path,OpenOption... options) throwsIOException
Files.newInputStream(java.nio.file.Path, java.nio.file.OpenOption...) method. The default implementation of this method opens a channel to the file as if by invoking thenewByteChannel(java.nio.file.Path, java.util.Set<? extends java.nio.file.OpenOption>, java.nio.file.attribute.FileAttribute<?>...) method and constructs a stream that reads bytes from the channel. This method should be overridden where appropriate.
path - the path to the file to openoptions - options specifying how the file is openedIllegalArgumentException - if an invalid combination of options is specifiedUnsupportedOperationException - if an unsupported option is specifiedIOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, thecheckRead method is invoked to check read access to the file.public OutputStream newOutputStream(Path path,OpenOption... options) throwsIOException
Files.newOutputStream(java.nio.file.Path, java.nio.file.OpenOption...) method. The default implementation of this method opens a channel to the file as if by invoking thenewByteChannel(java.nio.file.Path, java.util.Set<? extends java.nio.file.OpenOption>, java.nio.file.attribute.FileAttribute<?>...) method and constructs a stream that writes bytes to the channel. This method should be overridden where appropriate.
path - the path to the file to open or createoptions - options specifying how the file is openedIllegalArgumentException - ifoptions contains an invalid combination of optionsUnsupportedOperationException - if an unsupported option is specifiedIOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, thecheckWrite method is invoked to check write access to the file. ThecheckDelete method is invoked to check delete access if the file is opened with theDELETE_ON_CLOSE option.public FileChannel newFileChannel(Path path,Set<? extendsOpenOption> options,FileAttribute<?>... attrs) throwsIOException
FileChannel.open method. A provider that does not support all the features required to construct a file channel throwsUnsupportedOperationException. The default provider is required to support the creation of file channels. When not overridden, the default implementation throwsUnsupportedOperationException.path - the path of the file to open or createoptions - options specifying how the file is openedattrs - an optional list of file attributes to set atomically when creating the fileIllegalArgumentException - If the set contains an invalid combination of optionsUnsupportedOperationException - If this provider that does not support creating file channels, or an unsupported open option or file attribute is specifiedIOException - If an I/O error occursSecurityException - In the case of the default file system, theSecurityManager.checkRead(String) method is invoked to check read access if the file is opened for reading. TheSecurityManager.checkWrite(String) method is invoked to check write access if the file is opened for writingpublic AsynchronousFileChannel newAsynchronousFileChannel(Path path,Set<? extendsOpenOption> options,ExecutorService executor,FileAttribute<?>... attrs) throwsIOException
AsynchronousFileChannel.open method. A provider that does not support all the features required to construct an asynchronous file channel throwsUnsupportedOperationException. The default provider is required to support the creation of asynchronous file channels. When not overridden, the default implementation of this method throwsUnsupportedOperationException.path - the path of the file to open or createoptions - options specifying how the file is openedexecutor - the thread pool ornull to associate the channel with the default thread poolattrs - an optional list of file attributes to set atomically when creating the fileIllegalArgumentException - If the set contains an invalid combination of optionsUnsupportedOperationException - If this provider that does not support creating asynchronous file channels, or an unsupported open option or file attribute is specifiedIOException - If an I/O error occursSecurityException - In the case of the default file system, theSecurityManager.checkRead(String) method is invoked to check read access if the file is opened for reading. TheSecurityManager.checkWrite(String) method is invoked to check write access if the file is opened for writingpublic abstract SeekableByteChannel newByteChannel(Path path,Set<? extendsOpenOption> options,FileAttribute<?>... attrs) throwsIOException
Files.newByteChannel(Path,Set,FileAttribute[]) method.path - the path to the file to open or createoptions - options specifying how the file is openedattrs - an optional list of file attributes to set atomically when creating the fileIllegalArgumentException - if the set contains an invalid combination of optionsUnsupportedOperationException - if an unsupported open option is specified or the array contains attributes that cannot be set atomically when creating the fileFileAlreadyExistsException - if a file of that name already exists and theCREATE_NEW option is specified(optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, thecheckRead method is invoked to check read access to the path if the file is opened for reading. ThecheckWrite method is invoked to check write access to the path if the file is opened for writing. ThecheckDelete method is invoked to check delete access if the file is opened with theDELETE_ON_CLOSE option.public abstract DirectoryStream<Path> newDirectoryStream(Path dir,DirectoryStream.Filter<? superPath> filter) throwsIOException
DirectoryStream to iterate over the entries in the directory. This method works in exactly the manner specified by theFiles.newDirectoryStream(java.nio.file.Path, java.nio.file.DirectoryStream.Filter) method.dir - the path to the directoryfilter - the directory stream filterDirectoryStream objectNotDirectoryException - if the file could not otherwise be opened because it is not a directory(optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, thecheckRead method is invoked to check read access to the directory.public abstract void createDirectory(Path dir,FileAttribute<?>... attrs) throwsIOException
Files.createDirectory(java.nio.file.Path, java.nio.file.attribute.FileAttribute<?>...) method.dir - the directory to createattrs - an optional list of file attributes to set atomically when creating the directoryUnsupportedOperationException - if the array contains an attribute that cannot be set atomically when creating the directoryFileAlreadyExistsException - if a directory could not otherwise be created because a file of that name already exists(optional specific exception)IOException - if an I/O error occurs or the parent directory does not existSecurityException - In the case of the default provider, and a security manager is installed, thecheckWrite method is invoked to check write access to the new directory.public void createSymbolicLink(Path link,Path target,FileAttribute<?>... attrs) throwsIOException
Files.createSymbolicLink(java.nio.file.Path, java.nio.file.Path, java.nio.file.attribute.FileAttribute<?>...) method. The default implementation of this method throwsUnsupportedOperationException.
link - the path of the symbolic link to createtarget - the target of the symbolic linkattrs - the array of attributes to set atomically when creating the symbolic linkUnsupportedOperationException - if the implementation does not support symbolic links or the array contains an attribute that cannot be set atomically when creating the symbolic linkFileAlreadyExistsException - if a file with the name already exists(optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, it deniesLinkPermission("symbolic") or itscheckWrite method denies write access to the path of the symbolic link.public void createLink(Path link,Path existing) throwsIOException
Files.createLink(java.nio.file.Path, java.nio.file.Path) method. The default implementation of this method throwsUnsupportedOperationException.
link - the link (directory entry) to createexisting - a path to an existing fileUnsupportedOperationException - if the implementation does not support adding an existing file to a directoryFileAlreadyExistsException - if the entry could not otherwise be created because a file of that name already exists(optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, it deniesLinkPermission("hard") or itscheckWrite method denies write access to either the link or the existing file.public abstract void delete(Path path) throwsIOException
Files.delete(java.nio.file.Path) method.path - the path to the file to deleteNoSuchFileException - if the file does not exist(optional specific exception)DirectoryNotEmptyException - if the file is a directory and could not otherwise be deleted because the directory is not empty(optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, theSecurityManager.checkDelete(String) method is invoked to check delete access to the filepublic boolean deleteIfExists(Path path) throwsIOException
Files.deleteIfExists(java.nio.file.Path) method. The default implementation of this method simply invokesdelete(java.nio.file.Path) ignoring theNoSuchFileException when the file does not exist. It may be overridden where appropriate.
path - the path to the file to deletetrue if the file was deleted by this method;false if the file could not be deleted because it did not existDirectoryNotEmptyException - if the file is a directory and could not otherwise be deleted because the directory is not empty(optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, theSecurityManager.checkDelete(String) method is invoked to check delete access to the filepublic Path readSymbolicLink(Path link) throwsIOException
Files.readSymbolicLink(java.nio.file.Path) method. The default implementation of this method throwsUnsupportedOperationException.
link - the path to the symbolic linkUnsupportedOperationException - if the implementation does not support symbolic linksNotLinkException - if the target could otherwise not be read because the file is not a symbolic link(optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, it checks thatFilePermission has been granted with the "readlink" action to read the link.public abstract void copy(Path source,Path target,CopyOption... options) throwsIOException
Files.copy(Path,Path,CopyOption[]) method except that both the source and target paths must be associated with this provider.source - the path to the file to copytarget - the path to the target fileoptions - options specifying how the copy should be doneUnsupportedOperationException - if the array contains a copy option that is not supportedFileAlreadyExistsException - if the target file exists but cannot be replaced because theREPLACE_EXISTING option is not specified(optional specific exception)DirectoryNotEmptyException - theREPLACE_EXISTING option is specified but the file cannot be replaced because it is a non-empty directory(optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, thecheckRead method is invoked to check read access to the source file, thecheckWrite is invoked to check write access to the target file. If a symbolic link is copied the security manager is invoked to checkLinkPermission("symbolic").public abstract void move(Path source,Path target,CopyOption... options) throwsIOException
Files.move(java.nio.file.Path, java.nio.file.Path, java.nio.file.CopyOption...) method except that both the source and target paths must be associated with this provider.source - the path to the file to movetarget - the path to the target fileoptions - options specifying how the move should be doneUnsupportedOperationException - if the array contains a copy option that is not supportedFileAlreadyExistsException - if the target file exists but cannot be replaced because theREPLACE_EXISTING option is not specified(optional specific exception)DirectoryNotEmptyException - theREPLACE_EXISTING option is specified but the file cannot be replaced because it is a non-empty directory(optional specific exception)AtomicMoveNotSupportedException - if the options array contains theATOMIC_MOVE option but the file cannot be moved as an atomic file system operation.IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, thecheckWrite method is invoked to check write access to both the source and target file.public abstract boolean isSameFile(Path path,Path path2) throwsIOException
Files.isSameFile(java.nio.file.Path, java.nio.file.Path) method.path - one path to the filepath2 - the other pathtrue if, and only if, the two paths locate the same fileIOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, thecheckRead method is invoked to check read access to both files.public abstract boolean isHidden(Path path) throwsIOException
Files.isHidden(java.nio.file.Path) method. This method is invoked by theisHidden method.
path - the path to the file to testtrue if the file is considered hiddenIOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, thecheckRead method is invoked to check read access to the file.public abstract FileStore getFileStore(Path path) throwsIOException
FileStore representing the file store where a file is located. This method works in exactly the manner specified by theFiles.getFileStore(java.nio.file.Path) method.path - the path to the fileIOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, thecheckRead method is invoked to check read access to the file, and in addition it checksRuntimePermission ("getFileStoreAttributes")public abstract void checkAccess(Path path,AccessMode... modes) throwsIOException
This method may be used by theisReadable,isWritable andisExecutable methods to check the accessibility of a file.
This method checks the existence of a file and that this Java virtual machine has appropriate privileges that would allow it access the file according to all of access modes specified in themodes parameter as follows:
| Value | Description |
|---|---|
READ | Checks that the file exists and that the Java virtual machine has permission to read the file. |
WRITE | Checks that the file exists and that the Java virtual machine has permission to write to the file, |
EXECUTE | Checks that the file exists and that the Java virtual machine has permission toexecute the file. The semantics may differ when checking access to a directory. For example, on UNIX systems, checking forEXECUTE access checks that the Java virtual machine has permission to search the directory in order to access file or subdirectories. |
If themodes parameter is of length zero, then the existence of the file is checked.
This method follows symbolic links if the file referenced by this object is a symbolic link. Depending on the implementation, this method may require to read file permissions, access control lists, or other file attributes in order to check the effective access to the file. To determine the effective access to a file may require access to several attributes and so in some implementations this method may not be atomic with respect to other file system operations.
path - the path to the file to checkmodes - The access modes to check; may have zero elementsUnsupportedOperationException - an implementation is required to support checking forREAD,WRITE, andEXECUTE access. This exception is specified to allow for theAccess enum to be extended in future releases.NoSuchFileException - if a file does not exist(optional specific exception)AccessDeniedException - the requested access would be denied or the access cannot be determined because the Java virtual machine has insufficient privileges or other reasons.(optional specific exception)IOException - if an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, thecheckRead is invoked when checking read access to the file or only the existence of the file, thecheckWrite is invoked when checking write access to the file, andcheckExec is invoked when checking execute access.public abstract <V extendsFileAttributeView> V getFileAttributeView(Path path,Class<V> type,LinkOption... options)
Files.getFileAttributeView(java.nio.file.Path, java.lang.Class<V>, java.nio.file.LinkOption...) method.V - TheFileAttributeView typepath - the path to the filetype - theClass object corresponding to the file attribute viewoptions - options indicating how symbolic links are handlednull if the attribute view type is not availablepublic abstract <A extendsBasicFileAttributes> A readAttributes(Path path,Class<A> type,LinkOption... options) throwsIOException
Files.readAttributes(Path,Class,LinkOption[]) method.A - TheBasicFileAttributes typepath - the path to the filetype - theClass of the file attributes required to readoptions - options indicating how symbolic links are handledUnsupportedOperationException - if an attributes of the given type are not supportedIOException - if an I/O error occursSecurityException - In the case of the default provider, a security manager is installed, itscheckRead method is invoked to check read access to the filepublic abstract Map<String,Object> readAttributes(Path path,String attributes,LinkOption... options) throwsIOException
Files.readAttributes(Path,String,LinkOption[]) method.path - the path to the fileattributes - the attributes to readoptions - options indicating how symbolic links are handledUnsupportedOperationException - if the attribute view is not availableIllegalArgumentException - if no attributes are specified or an unrecognized attributes is specifiedIOException - If an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, itscheckRead method denies read access to the file. If this method is invoked to read security sensitive attributes then the security manager may be invoke to check for additional permissions.public abstract void setAttribute(Path path,String attribute,Object value,LinkOption... options) throwsIOException
Files.setAttribute(java.nio.file.Path, java.lang.String, java.lang.Object, java.nio.file.LinkOption...) method.path - the path to the fileattribute - the attribute to setvalue - the attribute valueoptions - options indicating how symbolic links are handledUnsupportedOperationException - if the attribute view is not availableIllegalArgumentException - if the attribute name is not specified, or is not recognized, or the attribute value is of the correct type but has an inappropriate valueClassCastException - If the attribute value is not of the expected type or is a collection containing elements that are not of the expected typeIOException - If an I/O error occursSecurityException - In the case of the default provider, and a security manager is installed, itscheckWrite method denies write access to the file. If this method is invoked to set security sensitive attributes then the security manager may be invoked to check for additional permissions.