Top Description Fields Constructors Methods
java.nio.file.spi

public abstract Class FileSystemProvider

extends Object
Class Inheritance
Known Direct Subclasses
sun.nio.fs.AbstractFileSystemProvider, jdk.internal.jrtfs.JrtFileSystemProvider
Imports
java.nio.channels.AsynchronousFileChannel, .Channels, .FileChannel, .ReadableByteChannel, .SeekableByteChannel, .WritableByteChannel, java.nio.file.AccessDeniedException, .AccessMode, .AtomicMoveNotSupportedException, .CopyOption, .DirectoryNotEmptyException, .DirectoryStream, .FileAlreadyExistsException, .FileStore, .FileSystem, .FileSystemAlreadyExistsException, .FileSystemNotFoundException, .FileSystems, .Files, .LinkOption, .LinkPermission, .NoSuchFileException, .NotDirectoryException, .NotLinkException, .OpenOption, .Path, .StandardOpenOption, java.net.URI, java.io.InputStream, .OutputStream, .IOException, java.nio.file.attribute.BasicFileAttributes, .FileAttribute, .FileAttributeView, java.util.ArrayList, .Collections, .HashSet, .List, .Map, .ServiceConfigurationError, .ServiceLoader, .Set, java.util.concurrent.ExecutorService, java.security.AccessController, .PrivilegedAction, sun.nio.ch.FileChannelImpl

Service-provider class for file systems. The methods defined by the java.nio.file.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 a URI scheme. The default provider is identified by the URI scheme "file". It creates the FileSystem that provides access to the file systems accessible to the Java virtual machine. The FileSystems 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 property java.nio.file.spi.DefaultFileSystemProvider is set. In that case, the provider has a one argument constructor whose formal parameter type is FileSystemProvider. All other providers have a zero argument constructor that initializes the provider.

A provider is a factory for one or more FileSystem instances. Each file system is identified by a URI where the URI's scheme matches the provider's scheme. 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". The newFileSystem method may be used to create a file system, and the getFileSystem 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 the newFileSystem method is invoked. In the case of the default provider, the FileSystem is created when the provider is initialized.

All of the methods in this class are safe for use by multiple concurrent threads.

Since
1.7

Field Summary

Modifier and TypeField and Description
private static final Set<OpenOption>
private static volatile List<FileSystemProvider>
private static boolean
private static final Object

Constructor Summary

AccessConstructor and Description
private
protected
FileSystemProvider()

Initializes a new instance of this class.

Method Summary

Modifier and TypeMethod and Description
public abstract void
checkAccess(Path
the path to the file to check
path
,
AccessMode...
The access modes to check; may have zero elements
modes
)

Checks the existence, and optionally the accessibility, of a file.

private static Void
public abstract void
copy(Path
the path to the file to copy
source
,
Path
the path to the target file
target
,
CopyOption...
options specifying how the copy should be done
options
)

Copy a file to a target file.

public abstract void
createDirectory(Path
the directory to create
dir
,
FileAttribute<?>...
an optional list of file attributes to set atomically when creating the directory
attrs
)

Creates a new directory.

public abstract void
delete(Path
the path to the file to delete
path
)

Deletes a file.

public boolean

Returns:

true if the file was deleted by this method; false if the file could not be deleted because it did not exist
deleteIfExists
(Path
the path to the file to delete
path
)

Deletes a file if it exists.

public boolean

Returns:

true if the file exists; false if the file does not exist or its existence cannot be determined.
exists
(Path
the path to the file to test
path
,
LinkOption...
options indicating how symbolic links are handled
options
)

Tests whether a file exists.

public abstract <
The FileAttributeView type
V extends FileAttributeView
>
V

Returns:

a file attribute view of the specified type, or null if the attribute view type is not available
getFileAttributeView
(Path
the path to the file
path
,
Class<V>
the Class object corresponding to the file attribute view
type
,
LinkOption...
options indicating how symbolic links are handled
options
)

Returns a file attribute view of a given type.

public abstract FileStore

Returns:

the file store where the file is stored
getFileStore
(Path
the path to the file
path
)

Returns the FileStore representing the file store where a file is located.

public abstract FileSystem

Returns:

The file system
getFileSystem
(URI
URI reference
uri
)

Returns an existing FileSystem created by this provider.

public abstract Path

Returns:

The resulting Path
getPath
(URI
The URI to convert
uri
)

Return a Path object by converting the given URI.

public abstract String

Returns:

The URI scheme
getScheme
()

Returns the URI scheme that identifies this provider.

public static List<FileSystemProvider>

Returns:

An unmodifiable list of the installed file system providers. The list contains at least one element, that is the default file system provider
installedProviders
()

Returns a list of the installed file system providers.

public abstract boolean

Returns:

true if the file is considered hidden
isHidden
(Path
the path to the file to test
path
)

Tells whether or not a file is considered hidden.

public abstract boolean

Returns:

true if, and only if, the two paths locate the same file
isSameFile
(Path
one path to the file
path
,
Path
the other path
path2
)

Tests if two paths locate the same file.

private static List<FileSystemProvider>
public abstract void
move(Path
the path to the file to move
source
,
Path
the path to the target file
target
,
CopyOption...
options specifying how the move should be done
options
)

Move or rename a file to a target file.

public AsynchronousFileChannel

Returns:

a new asynchronous file channel
newAsynchronousFileChannel
(Path
the path of the file to open or create
path
,
Set<? extends OpenOption>
options specifying how the file is opened
options
,
ExecutorService
the thread pool or null to associate the channel with the default thread pool
executor
,
FileAttribute<?>...
an optional list of file attributes to set atomically when creating the file
attrs
)

Opens or creates a file for reading and/or writing, returning an asynchronous file channel to access the file.

public abstract SeekableByteChannel

Returns:

a new seekable byte channel
newByteChannel
(Path
the path to the file to open or create
path
,
Set<? extends OpenOption>
options specifying how the file is opened
options
,
FileAttribute<?>...
an optional list of file attributes to set atomically when creating the file
attrs
)

Opens or creates a file, returning a seekable byte channel to access the file.

public abstract DirectoryStream<Path>

Returns:

a new and open DirectoryStream object
newDirectoryStream
(Path
the path to the directory
dir
,
DirectoryStream.Filter<? super Path>
the directory stream filter
filter
)

Opens a directory, returning a DirectoryStream to iterate over the entries in the directory.

public FileChannel

Returns:

a new file channel
newFileChannel
(Path
the path of the file to open or create
path
,
Set<? extends OpenOption>
options specifying how the file is opened
options
,
FileAttribute<?>...
an optional list of file attributes to set atomically when creating the file
attrs
)

Opens or creates a file for reading and/or writing, returning a file channel to access the file.

public abstract FileSystem

Returns:

A new file system
newFileSystem
(URI
URI reference
uri
,
Map<String, ?>
A map of provider specific properties to configure the file system; may be empty
env
)

Constructs a new FileSystem object identified by a URI.

public FileSystem

Returns:

A new file system
newFileSystem
(Path
The path to the file
path
,
Map<String, ?>
A map of provider specific properties to configure the file system; may be empty
env
)

Constructs a new FileSystem to access the contents of a file as a file system.

public InputStream

Returns:

a new input stream
newInputStream
(Path
the path to the file to open
path
,
OpenOption...
options specifying how the file is opened
options
)

Opens a file, returning an input stream to read from the file.

public OutputStream

Returns:

a new output stream
newOutputStream
(Path
the path to the file to open or create
path
,
OpenOption...
options specifying how the file is opened
options
)

Opens or creates a file, returning an output stream that may be used to write bytes to the file.

public abstract <
The BasicFileAttributes type
A extends BasicFileAttributes
>
A

Returns:

the file attributes
readAttributes
(Path
the path to the file
path
,
Class<A>
the Class of the file attributes required to read
type
,
LinkOption...
options indicating how symbolic links are handled
options
)

Reads a file's attributes as a bulk operation.

public abstract Map<String, Object>

Returns:

a map of the attributes returned; may be empty. The map's keys are the attribute names, its values are the attribute values
readAttributes
(Path
the path to the file
path
,
String
the attributes to read
attributes
,
LinkOption...
options indicating how symbolic links are handled
options
)

Reads a set of file attributes as a bulk operation.

public <
The BasicFileAttributes type
A extends BasicFileAttributes
>
A

Returns:

the file attributes or null if the file does not exist
readAttributesIfExists
(Path
the path to the file
path
,
Class<A>
the Class of the file attributes required to read
type
,
LinkOption...
options indicating how symbolic links are handled
options
)

Reads a file's attributes as a bulk operation if it exists.

public abstract void
setAttribute(Path
the path to the file
path
,
String
the attribute to set
attribute
,
Object
the attribute value
value
,
LinkOption...
options indicating how symbolic links are handled
options
)

Sets the value of a file attribute.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_OPEN_OPTIONSback to summary
private static final Set<OpenOption> DEFAULT_OPEN_OPTIONS
installedProvidersback to summary
private static volatile List<FileSystemProvider> installedProviders
loadingProvidersback to summary
private static boolean loadingProviders
lockback to summary
private static final Object lock

Constructor Detail

FileSystemProviderback to summary
private FileSystemProvider(Void ignore)
FileSystemProviderback to summary
protected FileSystemProvider()

Initializes a new instance of this class.

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.

Exceptions
SecurityException:
If a security manager has been installed and it denies RuntimePermission("fileSystemProvider")

Method Detail

checkAccessback to summary
public abstract void checkAccess(Path path, AccessMode... modes) throws IOException

Checks the existence, and optionally the accessibility, of a file.

This method may be used by the isReadable, isWritable and isExecutable 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 the modes parameter as follows:

Access Modes
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 to execute the file. The semantics may differ when checking access to a directory. For example, on UNIX systems, checking for EXECUTE access checks that the Java virtual machine has permission to search the directory in order to access file or subdirectories.

If the modes 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.

Parameters
path:Path

the path to the file to check

modes:AccessMode[]

The access modes to check; may have zero elements

Exceptions
IOException:
if an I/O error occurs
UnsupportedOperationException:
an implementation is required to support checking for READ, WRITE, and EXECUTE access. This exception is specified to allow for the Access 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)
SecurityException:
In the case of the default provider, and a security manager is installed, the checkRead is invoked when checking read access to the file or only the existence of the file, the checkWrite is invoked when checking write access to the file, and checkExec is invoked when checking execute access.
checkPermissionback to summary
private static Void checkPermission()
copyback to summary
public abstract void copy(Path source, Path target, CopyOption... options) throws IOException

Copy a file to a target file. This method works in exactly the manner specified by the Files#copy(Path, Path, CopyOption[]) method except that both the source and target paths must be associated with this provider.

Parameters
source:Path

the path to the file to copy

target:Path

the path to the target file

options:CopyOption[]

options specifying how the copy should be done

Exceptions
IOException:
if an I/O error occurs
UnsupportedOperationException:
if the array contains a copy option that is not supported
FileAlreadyExistsException:
if the target file exists but cannot be replaced because the REPLACE_EXISTING option is not specified (optional specific exception)
DirectoryNotEmptyException:
the REPLACE_EXISTING option is specified but the file cannot be replaced because it is a non-empty directory (optional specific exception)
SecurityException:
In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the source file, the checkWrite is invoked to check write access to the target file. If a symbolic link is copied the security manager is invoked to check LinkPermission("symbolic").
createDirectoryback to summary
public abstract void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException

Creates a new directory. This method works in exactly the manner specified by the Files#createDirectory method.

Parameters
dir:Path

the directory to create

attrs:FileAttribute<?>[]

an optional list of file attributes to set atomically when creating the directory

Exceptions
IOException:
if an I/O error occurs or the parent directory does not exist
UnsupportedOperationException:
if the array contains an attribute that cannot be set atomically when creating the directory
FileAlreadyExistsException:
if a directory could not otherwise be created because a file of that name already exists (optional specific exception)
SecurityException:
In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access to the new directory.
deleteback to summary
public abstract void delete(Path path) throws IOException

Deletes a file. This method works in exactly the manner specified by the Files#delete method.

Parameters
path:Path

the path to the file to delete

Exceptions
IOException:
if an I/O error occurs
NoSuchFileException:
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)
SecurityException:
In the case of the default provider, and a security manager is installed, the SecurityManager#checkDelete(String) method is invoked to check delete access to the file
deleteIfExistsback to summary
public boolean deleteIfExists(Path path) throws IOException

Deletes a file if it exists. This method works in exactly the manner specified by the Files#deleteIfExists method.

The default implementation of this method simply invokes delete ignoring the NoSuchFileException when the file does not exist. It may be overridden where appropriate.

Parameters
path:Path

the path to the file to delete

Returns:boolean

true if the file was deleted by this method; false if the file could not be deleted because it did not exist

Exceptions
IOException:
if an I/O error occurs
DirectoryNotEmptyException:
if the file is a directory and could not otherwise be deleted because the directory is not empty (optional specific exception)
SecurityException:
In the case of the default provider, and a security manager is installed, the SecurityManager#checkDelete(String) method is invoked to check delete access to the file
existsback to summary
public boolean exists(Path path, LinkOption... options)

Tests whether a file exists. This method works in exactly the manner specified by the Files#exists(Path, LinkOption...) method.

Implementation Specification

The default implementation of this method invokes the checkAccess(Path, AccessMode...) method when symbolic links are followed. If the option NOFOLLOW_LINKS is present then symbolic links are not followed and the method readAttributes(Path, Class, LinkOption...) is called to determine whether a file exists.

Parameters
path:Path

the path to the file to test

options:LinkOption[]

options indicating how symbolic links are handled

Returns:boolean

true if the file exists; false if the file does not exist or its existence cannot be determined.

Exceptions
SecurityException:
In the case of the default provider, the SecurityManager#checkRead(String) is invoked to check read access to the file.
Since
20
getFileAttributeViewback to summary
public abstract <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options)

Returns a file attribute view of a given type. This method works in exactly the manner specified by the Files#getFileAttributeView method.

Parameters
<V>
The FileAttributeView type
path:Path

the path to the file

type:Class<V>

the Class object corresponding to the file attribute view

options:LinkOption[]

options indicating how symbolic links are handled

Returns:V

a file attribute view of the specified type, or null if the attribute view type is not available

getFileStoreback to summary
public abstract FileStore getFileStore(Path path) throws IOException

Returns the FileStore representing the file store where a file is located. This method works in exactly the manner specified by the Files#getFileStore method.

Parameters
path:Path

the path to the file

Returns:FileStore

the file store where the file is stored

Exceptions
IOException:
if an I/O error occurs
SecurityException:
In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the file, and in addition it checks RuntimePermission("getFileStoreAttributes")
getFileSystemback to summary
public abstract FileSystem getFileSystem(URI uri)

Returns an existing FileSystem created by this provider.

This method returns a reference to a FileSystem that was created by invoking the newFileSystem(URI,Map) method. File systems created the newFileSystem(Path,Map) method are not returned by this method. The file system is identified by its URI. 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 by null).

Once a file system created by this provider is closed it is provider-dependent if this method returns a reference to the closed file system or throws FileSystemNotFoundException. 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 the newFileSystem 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 the default file system, no permission check is required.

Parameters
uri:URI

URI reference

Returns:FileSystem

The file system

Exceptions
IllegalArgumentException:
If the pre-conditions for the uri parameter aren't met
FileSystemNotFoundException:
If the file system does not exist
SecurityException:
If a security manager is installed and it denies an unspecified permission.
getPathback to summary
public abstract Path getPath(URI uri)

Return a Path object by converting the given URI. The resulting Path is associated with a FileSystem 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 resulting Path is associated with the default default FileSystem.

If a security manager is installed then a provider implementation may require to check a permission. In the case of the default file system, no permission check is required.

Parameters
uri:URI

The URI to convert

Returns:Path

The resulting Path

Exceptions
IllegalArgumentException:
If the URI scheme does not identify this provider or other preconditions on the uri parameter do not hold
FileSystemNotFoundException:
The file system, identified by the URI, does not exist and cannot be created automatically
SecurityException:
If a security manager is installed and it denies an unspecified permission.
getSchemeback to summary
public abstract String getScheme()

Returns the URI scheme that identifies this provider.

Returns:String

The URI scheme

installedProvidersback to summary
public static List<FileSystemProvider> installedProviders()

Returns a list of the installed file system providers.

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 the FileSystems class.

Returns:List<FileSystemProvider>

An unmodifiable list of the installed file system providers. The list contains at least one element, that is the default file system provider

Exceptions
ServiceConfigurationError:
When an error occurs while loading a service provider
isHiddenback to summary
public abstract boolean isHidden(Path path) throws IOException

Tells whether or not a file is considered hidden. This method works in exactly the manner specified by the Files#isHidden method.

This method is invoked by the isHidden method.

Parameters
path:Path

the path to the file to test

Returns:boolean

true if the file is considered hidden

Exceptions
IOException:
if an I/O error occurs
SecurityException:
In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the file.
isSameFileback to summary
public abstract boolean isSameFile(Path path, Path path2) throws IOException

Tests if two paths locate the same file. This method works in exactly the manner specified by the Files#isSameFile method.

Parameters
path:Path

one path to the file

path2:Path

the other path

Returns:boolean

true if, and only if, the two paths locate the same file

Exceptions
IOException:
if an I/O error occurs
SecurityException:
In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to both files.
loadInstalledProvidersback to summary
private static List<FileSystemProvider> loadInstalledProviders()
moveback to summary
public abstract void move(Path source, Path target, CopyOption... options) throws IOException

Move or rename a file to a target file. This method works in exactly the manner specified by the Files#move method except that both the source and target paths must be associated with this provider.

Parameters
source:Path

the path to the file to move

target:Path

the path to the target file

options:CopyOption[]

options specifying how the move should be done

Exceptions
IOException:
if an I/O error occurs
UnsupportedOperationException:
if the array contains a copy option that is not supported
FileAlreadyExistsException:
if the target file exists but cannot be replaced because the REPLACE_EXISTING option is not specified (optional specific exception)
DirectoryNotEmptyException:
the REPLACE_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 the ATOMIC_MOVE option but the file cannot be moved as an atomic file system operation.
SecurityException:
In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access to both the source and target file.
newAsynchronousFileChannelback to summary
public AsynchronousFileChannel newAsynchronousFileChannel(Path path, Set<? extends OpenOption> options, ExecutorService executor, FileAttribute<?>... attrs) throws IOException

Opens or creates a file for reading and/or writing, returning an asynchronous file channel to access the file. This method works in exactly the manner specified by the AsynchronousFileChannel.open method. A provider that does not support all the features required to construct an asynchronous file channel throws UnsupportedOperationException. The default provider is required to support the creation of asynchronous file channels. When not overridden, the default implementation of this method throws UnsupportedOperationException.

Parameters
path:Path

the path of the file to open or create

options:Set<? extends OpenOption>

options specifying how the file is opened

executor:ExecutorService

the thread pool or null to associate the channel with the default thread pool

attrs:FileAttribute<?>[]

an optional list of file attributes to set atomically when creating the file

Returns:AsynchronousFileChannel

a new asynchronous file channel

Exceptions
IOException:
If an I/O error occurs
IllegalArgumentException:
If the set contains an invalid combination of options
UnsupportedOperationException:
If this provider that does not support creating asynchronous file channels, or an unsupported open option or file attribute is specified
FileAlreadyExistsException:
If a file of that name already exists and the CREATE_NEW option is specified and the file is being opened for writing (optional specific exception)
SecurityException:
In the case of the default file system, the SecurityManager#checkRead(String) method is invoked to check read access if the file is opened for reading. The SecurityManager#checkWrite(String) method is invoked to check write access if the file is opened for writing
newByteChannelback to summary
public abstract SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException

Opens or creates a file, returning a seekable byte channel to access the file. This method works in exactly the manner specified by the Files#newByteChannel(Path, Set, FileAttribute[]) method.

Parameters
path:Path

the path to the file to open or create

options:Set<? extends OpenOption>

options specifying how the file is opened

attrs:FileAttribute<?>[]

an optional list of file attributes to set atomically when creating the file

Returns:SeekableByteChannel

a new seekable byte channel

Exceptions
IOException:
if an I/O error occurs
IllegalArgumentException:
if the set contains an invalid combination of options
UnsupportedOperationException:
if an unsupported open option is specified or the array contains attributes that cannot be set atomically when creating the file
FileAlreadyExistsException:
If a file of that name already exists and the CREATE_NEW option is specified and the file is being opened for writing (optional specific exception)
SecurityException:
In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the path if the file is opened for reading. The checkWrite method is invoked to check write access to the path if the file is opened for writing. The checkDelete method is invoked to check delete access if the file is opened with the DELETE_ON_CLOSE option.
newDirectoryStreamback to summary
public abstract DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException

Opens a directory, returning a DirectoryStream to iterate over the entries in the directory. This method works in exactly the manner specified by the Files#newDirectoryStream(java.nio.file.Path, java.nio.file.DirectoryStream.Filter) method.

Parameters
dir:Path

the path to the directory

filter:DirectoryStream.Filter<? super Path>

the directory stream filter

Returns:DirectoryStream<Path>

a new and open DirectoryStream object

Exceptions
IOException:
if an I/O error occurs
NotDirectoryException:
if the file could not otherwise be opened because it is not a directory (optional specific exception)
SecurityException:
In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the directory.
newFileChannelback to summary
public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException

Opens or creates a file for reading and/or writing, returning a file channel to access the file. This method works in exactly the manner specified by the FileChannel.open method. A provider that does not support all the features required to construct a file channel throws UnsupportedOperationException. The default provider is required to support the creation of file channels. When not overridden, the default implementation throws UnsupportedOperationException.

Parameters
path:Path

the path of the file to open or create

options:Set<? extends OpenOption>

options specifying how the file is opened

attrs:FileAttribute<?>[]

an optional list of file attributes to set atomically when creating the file

Returns:FileChannel

a new file channel

Exceptions
IOException:
If an I/O error occurs
IllegalArgumentException:
If the set contains an invalid combination of options
UnsupportedOperationException:
If this provider that does not support creating file channels, or an unsupported open option or file attribute is specified
FileAlreadyExistsException:
If a file of that name already exists and the CREATE_NEW option is specified and the file is being opened for writing (optional specific exception)
SecurityException:
In the case of the default file system, the SecurityManager#checkRead(String) method is invoked to check read access if the file is opened for reading. The SecurityManager#checkWrite(String) method is invoked to check write access if the file is opened for writing
newFileSystemback to summary
public abstract FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException

Constructs a new FileSystem object identified by a URI. This method is invoked by the FileSystems#newFileSystem(URI, Map) method to open a new file system identified by a URI.

The uri 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. The env parameter is a map of provider specific properties to configure the file system.

This method throws FileSystemAlreadyExistsException if the file system already exists because it was previously created by an invocation of this method. Once a file system is closed 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.

Parameters
uri:URI

URI reference

env:Map<String, ?>

A map of provider specific properties to configure the file system; may be empty

Returns:FileSystem

A new file system

Exceptions
IOException:
An I/O error occurs creating the file system
IllegalArgumentException:
If the pre-conditions for the uri parameter aren't met, or the env parameter does not contain properties required by the provider, or a property value is invalid
SecurityException:
If a security manager is installed and it denies an unspecified permission required by the file system provider implementation
FileSystemAlreadyExistsException:
If the file system has already been created
newFileSystemback to summary
public FileSystem newFileSystem(Path path, Map<String, ?> env) throws IOException

Constructs a new 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. The env 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 throws UnsupportedOperationException. The default implementation of this method throws UnsupportedOperationException.

Parameters
path:Path

The path to the file

env:Map<String, ?>

A map of provider specific properties to configure the file system; may be empty

Returns:FileSystem

A new file system

Exceptions
IOException:
If an I/O error occurs
UnsupportedOperationException:
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 file
IllegalArgumentException:
If the env parameter does not contain properties required by the provider, or a property value is invalid
SecurityException:
If a security manager is installed and it denies an unspecified permission.
newInputStreamback to summary
public InputStream newInputStream(Path path, OpenOption... options) throws IOException

Opens a file, returning an input stream to read from the file. This method works in exactly the manner specified by the Files#newInputStream method.

The default implementation of this method opens a channel to the file as if by invoking the newByteChannel method and constructs a stream that reads bytes from the channel. This method should be overridden where appropriate.

Parameters
path:Path

the path to the file to open

options:OpenOption[]

options specifying how the file is opened

Returns:InputStream

a new input stream

Exceptions
IOException:
if an I/O error occurs
IllegalArgumentException:
if an invalid combination of options is specified
UnsupportedOperationException:
if an unsupported option is specified
SecurityException:
In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the file.
newOutputStreamback to summary
public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException

Opens or creates a file, returning an output stream that may be used to write bytes to the file. This method works in exactly the manner specified by the Files#newOutputStream method.

The default implementation of this method opens a channel to the file as if by invoking the newByteChannel method and constructs a stream that writes bytes to the channel. This method should be overridden where appropriate.

Parameters
path:Path

the path to the file to open or create

options:OpenOption[]

options specifying how the file is opened

Returns:OutputStream

a new output stream

Exceptions
IOException:
if an I/O error occurs
IllegalArgumentException:
if options contains an invalid combination of options
UnsupportedOperationException:
if an unsupported option is specified
FileAlreadyExistsException:
If a file of that name already exists and the CREATE_NEW option is specified (optional specific exception)
SecurityException:
In the case of the default provider, and a security manager is installed, the checkWrite method is invoked to check write access to the file. The checkDelete method is invoked to check delete access if the file is opened with the DELETE_ON_CLOSE option.
readAttributesback to summary
public abstract <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException

Reads a file's attributes as a bulk operation. This method works in exactly the manner specified by the Files#readAttributes(Path, Class, LinkOption[]) method.

Parameters
<A>
The BasicFileAttributes type
path:Path

the path to the file

type:Class<A>

the Class of the file attributes required to read

options:LinkOption[]

options indicating how symbolic links are handled

Returns:A

the file attributes

Exceptions
IOException:
if an I/O error occurs
UnsupportedOperationException:
if an attributes of the given type are not supported
SecurityException:
In the case of the default provider, a security manager is installed, its checkRead method is invoked to check read access to the file
readAttributesback to summary
public abstract Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException

Reads a set of file attributes as a bulk operation. This method works in exactly the manner specified by the Files#readAttributes(Path, String, LinkOption[]) method.

Parameters
path:Path

the path to the file

attributes:String

the attributes to read

options:LinkOption[]

options indicating how symbolic links are handled

Returns:Map<String, Object>

a map of the attributes returned; may be empty. The map's keys are the attribute names, its values are the attribute values

Exceptions
IOException:
If an I/O error occurs
UnsupportedOperationException:
if the attribute view is not available
IllegalArgumentException:
if no attributes are specified or an unrecognized attributes is specified
SecurityException:
In the case of the default provider, and a security manager is installed, its checkRead method denies read access to the file. If this method is invoked to read security sensitive attributes then the security manager may be invoked to check for additional permissions.
readAttributesIfExistsback to summary
public <A extends BasicFileAttributes> A readAttributesIfExists(Path path, Class<A> type, LinkOption... options) throws IOException

Reads a file's attributes as a bulk operation if it exists.

The type parameter is the type of the attributes required and this method returns an instance of that type if supported. All implementations support a basic set of file attributes and so invoking this method with a type parameter of BasicFileAttributes.class will not throw UnsupportedOperationException.

The options array may be used to indicate how symbolic links are handled for the case that the file is a symbolic link. By default, symbolic links are followed and the file attribute of the final target of the link is read. If the option NOFOLLOW_LINKS is present then symbolic links are not followed.

It is implementation specific if all file attributes are read as an atomic operation with respect to other file system operations.

Implementation Specification

The default implementation of this method invokes the readAttributes(Path, Class, LinkOption...) method to read the file's attributes.

Parameters
<A>
The BasicFileAttributes type
path:Path

the path to the file

type:Class<A>

the Class of the file attributes required to read

options:LinkOption[]

options indicating how symbolic links are handled

Returns:A

the file attributes or null if the file does not exist

Exceptions
IOException:
if an I/O error occurs
UnsupportedOperationException:
if an attributes of the given type are not supported
SecurityException:
In the case of the default provider, a security manager is installed, its checkRead method is invoked to check read access to the file. If this method is invoked to read security sensitive attributes then the security manager may be invoked to check for additional permissions.
Since
20
setAttributeback to summary
public abstract void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException

Sets the value of a file attribute. This method works in exactly the manner specified by the Files#setAttribute method.

Parameters
path:Path

the path to the file

attribute:String

the attribute to set

value:Object

the attribute value

options:LinkOption[]

options indicating how symbolic links are handled

Exceptions
IOException:
If an I/O error occurs
UnsupportedOperationException:
if the attribute view is not available
IllegalArgumentException:
if the attribute name is not specified, or is not recognized, or the attribute value is of the correct type but has an inappropriate value
ClassCastException:
If the attribute value is not of the expected type or is a collection containing elements that are not of the expected type
SecurityException:
In the case of the default provider, and a security manager is installed, its checkWrite 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.