The default file system, obtained by invoking the FileSystems.
method, provides access to the file system that is
accessible to the Java virtual machine. The FileSystems
class defines
methods to create file systems that provide access to other types of (custom)
file systems.
A file system is the factory for several types of objects:
The getPath
method converts a system dependent
path string, returning a Path
object that may be used
to locate and access a file.
The getPathMatcher
method is used
to create a PathMatcher
that performs match operations on
paths.
The getFileStores
method returns an iterator
over the underlying file-stores
.
The getUserPrincipalLookupService
method returns the UserPrincipalLookupService
to lookup users or
groups by name.
The newWatchService
method creates a
WatchService
that may be used to watch objects for changes and
events.
File systems vary greatly. In some cases the file system is a single
hierarchy of files with one top-level root directory. In other cases it may
have several distinct file hierarchies, each with its own top-level root
directory. The getRootDirectories
method may be
used to iterate over the root directories in the file system. A file system
is typically composed of one or more underlying file-stores
that provide the storage for the files. These file stores can also vary in
the features they support, and the file attributes or meta-data that
they associate with files.
A file system is open upon creation and can be closed by invoking its
close
method. Once closed, any further attempt to access
objects in the file system cause ClosedFileSystemException
to be
thrown. File systems created by the default provider
cannot be closed.
A FileSystem
can provide read-only or read-write access to the
file system. Whether or not a file system provides read-only access is
established when the FileSystem
is created and can be tested by invoking
its isReadOnly
method. Attempts to write to file stores
by means of an object associated with a read-only file system throws ReadOnlyFileSystemException
.
File systems are safe for use by multiple concurrent threads. The close
method may be invoked at any time to close a file system but
whether a file system is asynchronously closeable is provider specific
and therefore unspecified. In other words, if a thread is accessing an
object in a file system, and another thread invokes the close
method
then it may require to block until the first operation is complete. Closing
a file system causes all open channels, watch services, and other closeable
objects associated with the file system to be closed.
Access | Constructor and Description |
---|---|
protected |
Modifier and Type | Method and Description |
---|---|
public abstract void | |
public abstract Iterable | Returns: An object to iterate over the backing file storesReturns an object to iterate over the underlying file stores. |
public abstract Path | |
public abstract PathMatcher | Returns: A path matcher that may be used to match paths against the patternThe syntax and pattern syntaxAndPattern)Returns a |
public abstract Iterable | Returns: An object to iterate over the root directoriesReturns an object to iterate over the paths of the root directories. |
public abstract String | |
public abstract UserPrincipalLookupService | Returns: TheUserPrincipalLookupService for this file systemReturns the |
public abstract boolean | Returns: true if, and only if, this file system is openTells whether or not this file system is open. |
public abstract boolean | Returns: true if, and only if, this file system provides
read-only accessTells whether or not this file system allows only read-only access to its file stores. |
public abstract WatchService | |
public abstract FileSystemProvider | Returns: The provider that created this file system.Returns the provider that created this file system. |
public abstract Set | Returns: An unmodifiable set of the names of the supported file attribute viewsReturns the set of the |
FileSystem | back to summary |
---|---|
protected FileSystem() Initializes a new instance of this class. |
close | back to summary |
---|---|
public abstract void close() throws IOException Redeclares java. Closes this file system. After a file system is closed then all subsequent access to the file
system, either by methods defined by this class or on objects associated
with this file system, throw Closing a file system will close all open
|
getFileStores | back to summary |
---|---|
public abstract Iterable Returns an object to iterate over the underlying file stores. The elements of the returned iterator are the In the case of the default provider, and a security manager is
installed, the security manager is invoked to check Usage Example: Suppose we want to print the space usage for all file stores: for (FileStore store: FileSystems.getDefault().getFileStores()) { long total = store.getTotalSpace() / 1024; long used = (store.getTotalSpace() - store.getUnallocatedSpace()) / 1024; long avail = store.getUsableSpace() / 1024; System.out.format("%-20s %12d %12d %12d%n", store, total, used, avail); } |
getPath | back to summary |
---|---|
public abstract Path getPath(String first, String... more) Converts a path string, or a sequence of strings that when joined form
a path string, to a The parsing and conversion to a path object is inherently
implementation dependent. In the simplest case, the path string is rejected,
and In the case of the default provider, path strings are parsed based on the definition of paths at the platform or virtual file system level. For example, an operating system may not allow specific characters to be present in a file name, but a specific underlying file store may impose different or additional restrictions on the set of legal characters. This method throws
|
getPathMatcher | back to summary | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
public abstract PathMatcher getPathMatcher(String syntaxAndPattern) Returns a where syntax is the non-empty name of the syntax, pattern is a possibly-empty pattern string, andsyntax:pattern ':' stands for itself.
A When the syntax is "
The following rules are used to interpret glob patterns:
When the syntax is " For both the glob and regex syntaxes, the matching details, such as whether the matching is case sensitive, are implementation-dependent and therefore not specified.
|
getRootDirectories | back to summary |
---|---|
public abstract Iterable Returns an object to iterate over the paths of the root directories. A file system provides access to a file store that may be composed of a number of distinct file hierarchies, each with its own top-level root directory. Unless denied by the security manager, each element in the returned iterator corresponds to the root directory of a distinct file hierarchy. The order of the elements is not defined. The file hierarchies may change during the lifetime of the Java virtual machine. For example, in some implementations, the insertion of removable media may result in the creation of a new file hierarchy with its own top-level directory. There is no guarantee that a root directory can be accessed. When a security manager is installed, it is invoked to check access
to the each root directory. If denied, the root directory is not returned
by the iterator. In the case of the default provider, the |
getSeparator | back to summary |
---|---|
public abstract String getSeparator() Returns the name separator, represented as a string. The name separator is used to separate names in a path string. An
implementation may support multiple name separators in which case this
method returns an implementation specific default name separator.
This separator is used when creating path strings by invoking the In the case of the default provider, this method returns the same
separator as
|
getUserPrincipalLookupService | back to summary |
---|---|
public abstract UserPrincipalLookupService getUserPrincipalLookupService() Returns the Usage Example: Suppose we want to make "joe" the owner of a file: UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService(); Files.setOwner(path, lookupService.lookupPrincipalByName("joe"));
|
isOpen | back to summary |
---|---|
public abstract boolean isOpen() Tells whether or not this file system is open. File systems created by the default provider are always open.
|
isReadOnly | back to summary |
---|---|
public abstract boolean isReadOnly() Tells whether or not this file system allows only read-only access to its file stores.
|
newWatchService | back to summary |
---|---|
public abstract WatchService newWatchService() throws IOException Constructs a new This method constructs a new watch service that may be used to watch registered objects for changes and events.
|
provider | back to summary |
---|---|
public abstract FileSystemProvider provider() Returns the provider that created this file system.
|
supportedFileAttributeViews | back to summary |
---|---|
public abstract Set Returns the set of the The The |