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.
Modifier and Type | Field and Description |
---|---|
private static final Set | |
private static volatile List | |
private static boolean | |
private static final Object |
Access | Constructor and Description |
---|---|
private | |
protected |
Modifier and Type | Method 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 void | createLink(Path
the link (directory entry) to create link, Path a path to an existing file existing)Creates a new link (directory entry) for an existing file. |
public void | createSymbolicLink(Path
the path of the symbolic link to create link, Path the target of the symbolic link target, FileAttribute<?>... the array of attributes to set atomically when creating the
symbolic link attrs)Creates a symbolic link to a target. |
public abstract void | |
public boolean | Returns: true if the file was deleted by this method; false if the file could not be deleted because it did not
existthe 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.the path to the file to test path, LinkOption... options indicating how symbolic links are handled options)Tests whether a file exists. |
private static boolean | |
public abstract < The V extends FileAttributeView> VFileAttributeView type | Returns: a file attribute view of the specified type, ornull if
the attribute view type is not availablethe path to the file path, Class<V> the type, LinkOption... Class object corresponding to the file attribute viewoptions 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 storedthe path to the file path)Returns the |
public abstract FileSystem | Returns: The file systemURI reference uri)Returns an existing |
public abstract Path | |
public abstract String | |
public static List | Returns: An unmodifiable list of the installed file system providers. The list contains at least one element, that is the default file system providerReturns a list of the installed file system providers. |
public abstract boolean | |
public abstract boolean | Returns: true if, and only if, the two paths locate the same fileone path to the file path, Path the other path path2)Tests if two paths locate the same file. |
private static List | |
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 channelthe 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 executor, FileAttribute<?>... null to associate the channel with
the default thread poolan 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 channelthe 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 | Returns: a new and openDirectoryStream objectthe path to the directory dir, DirectoryStream.the directory stream filter filterOpens a directory, returning a |
public FileChannel | Returns: a new file channelthe 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 systemURI reference uri, Map<String, ?> A map of provider specific properties to configure the file system;
may be empty env)Constructs a new |
public FileSystem | Returns: A new file systemThe 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 |
public InputStream | Returns: a new input streamthe 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 streamthe 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 A extends BasicFileAttributes> ABasicFileAttributes type | Returns: the file attributesthe path to the file path, Class<A> the type, LinkOption... Class of the file attributes required
to readoptions indicating how symbolic links are handled options)Reads a file's attributes as a bulk operation. |
public abstract Map | Returns: a map of the attributes returned; may be empty. The map's keys are the attribute names, its values are the attribute valuesthe 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 A extends BasicFileAttributes> ABasicFileAttributes type | Returns: the file attributes or null if the file does not existthe path to the file path, Class<A> the type, LinkOption... Class of the file attributes required
to readoptions indicating how symbolic links are handled options)Reads a file's attributes as a bulk operation if it exists. |
public Path | Returns: The target of the symbolic linkthe path to the symbolic link link)Reads the target of a symbolic link. |
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. |
DEFAULT_OPEN_OPTIONS | back to summary |
---|---|
private static final Set<OpenOption> DEFAULT_OPEN_OPTIONS |
installedProviders | back to summary |
---|---|
private static volatile List<FileSystemProvider> installedProviders |
loadingProviders | back to summary |
---|---|
private static boolean loadingProviders |
lock | back to summary |
---|---|
private static final Object lock |
FileSystemProvider | back to summary |
---|---|
private FileSystemProvider(Void ignore) |
FileSystemProvider | back 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.
|
checkAccess | back 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 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
If the 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.
|
checkPermission | back to summary |
---|---|
private static Void checkPermission() |
copy | back 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
|
createDirectory | back 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
|
createLink | back to summary |
---|---|
public void createLink(Path link, Path existing) throws IOException Creates a new link (directory entry) for an existing file. This method
works in exactly the manner specified by the The default implementation of this method throws
|
createSymbolicLink | back to summary |
---|---|
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) throws IOException Creates a symbolic link to a target. This method works in exactly the
manner specified by the The default implementation of this method throws
|
delete | back to summary |
---|---|
public abstract void delete(Path path) throws IOException Deletes a file. This method works in exactly the manner specified by the
|
deleteIfExists | back 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 The default implementation of this method simply invokes
|
exists | back to summary |
---|---|
public boolean exists(Path path, LinkOption... options) Tests whether a file exists. This method works in exactly the
manner specified by the Implementation Specification The default implementation of this method invokes the
|
followLinks | back to summary |
---|---|
private static boolean followLinks(LinkOption... options) |
getFileAttributeView | back 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
|
getFileStore | back to summary |
---|---|
public abstract FileStore getFileStore(Path path) throws IOException Returns the
|
getFileSystem | back to summary |
---|---|
public abstract FileSystem getFileSystem(URI uri) Returns an existing This method returns a reference to a Once a file system created by this provider is 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
|
getPath | back to summary |
---|---|
public abstract Path getPath(URI uri) Return a The exact form of the URI is file system provider dependent. In the
case of the default provider, the URI scheme is If a security manager is installed then a provider implementation
may require to check a permission. In the case of the
|
getScheme | back to summary |
---|---|
public abstract String getScheme() Returns the URI scheme that identifies this provider.
|
installedProviders | back to summary |
---|---|
public static List 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
|
isHidden | back 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 This method is invoked by the
|
isSameFile | back 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
|
loadInstalledProviders | back to summary |
---|---|
private static List |
move | back 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
|
newAsynchronousFileChannel | back 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
|
newByteChannel | back 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
|
newDirectoryStream | back to summary |
---|---|
public abstract DirectoryStream Opens a directory, returning a
|
newFileChannel | back 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
|
newFileSystem | back to summary |
---|---|
public abstract FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException Constructs a new The This method throws
|
newFileSystem | back to summary |
---|---|
public FileSystem newFileSystem(Path path, Map<String, ?> env) throws IOException Constructs a new 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 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
|
newInputStream | back 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 The default implementation of this method opens a channel to the file
as if by invoking the
|
newOutputStream | back 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 The default implementation of this method opens a channel to the file
as if by invoking the
|
readAttributes | back 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
|
readAttributes | back to summary |
---|---|
public abstract Map Reads a set of file attributes as a bulk operation. This method works in
exactly the manner specified by the
|
readAttributesIfExists | back 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 The 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
|
readSymbolicLink | back to summary |
---|---|
public Path readSymbolicLink(Path link) throws IOException Reads the target of a symbolic link. This method works in exactly the
manner specified by the The default implementation of this method throws
|
setAttribute | back 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
|