Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/java/nio/file/FileSystems#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/java/nio/file/FileSystems#inhmethods)

# FileSystems

` public final class FileSystems `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.nio.file.FileSystems |

<br />

*** ** * ** ***

Factory methods for file systems. This class defines the `https://developer.android.com/reference/java/nio/file/FileSystems#getDefault()` method to get the default file system and factory methods to construct other types of file systems.

The first invocation of any of the methods defined by this class causes the default `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider` to be loaded. The default provider, identified by the URI scheme "file", creates the `https://developer.android.com/reference/java/nio/file/FileSystem` that provides access to the file systems accessible to the Java virtual machine. If the process of loading or initializing the default provider fails then an unspecified error is thrown.

The first invocation of the `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#installedProviders()` method, by way of invoking any of the `newFileSystem` methods defined by this class, locates and loads all installed file system providers. Installed providers are loaded using the service-provider loading facility defined by the `https://developer.android.com/reference/java/util/ServiceLoader` class. Installed providers are loaded using the system class loader. If the system class loader cannot be found then the platform class loader is used. Providers are typically installed by placing them in a JAR file on the application class path, the JAR file contains a provider-configuration file named `java.nio.file.spi.FileSystemProvider` in the resource directory `META-INF/services`, and the file lists one or more fully-qualified names of concrete subclass of `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider` that have a zero argument constructor. The ordering that installed providers are located is implementation specific. If a provider is instantiated and its `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#getScheme()` returns the same URI scheme of a provider that was previously instantiated then the most recently instantiated duplicate is discarded. URI schemes are compared without regard to case. 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.

This class also defines factory methods that allow a `https://developer.android.com/reference/java/lang/ClassLoader` to be specified when locating a provider. As with installed providers, the provider classes are identified by placing the provider configuration file in the resource directory `META-INF/services`.

If a thread initiates the loading of the installed file system providers and another thread invokes a method that also attempts to load the providers then the method will block until the loading completes.

## Summary

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/java/nio/file/FileSystem` | ` https://developer.android.com/reference/java/nio/file/FileSystems#getDefault()() ` Returns the default `FileSystem`. |
| ` static https://developer.android.com/reference/java/nio/file/FileSystem` | ` https://developer.android.com/reference/java/nio/file/FileSystems#getFileSystem(java.net.URI)(https://developer.android.com/reference/java/net/URI uri) ` Returns a reference to an existing `FileSystem`. |
| ` static https://developer.android.com/reference/java/nio/file/FileSystem` | ` https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.net.URI,%20java.util.Map<java.lang.String,?>)(https://developer.android.com/reference/java/net/URI uri, https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/String, ?> env) ` Constructs a new file system that is identified by a `https://developer.android.com/reference/java/net/URI` This method iterates over the `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#installedProviders()` providers to locate the provider that is identified by the URI `https://developer.android.com/reference/java/net/URI#getScheme()` of the given URI. |
| ` static https://developer.android.com/reference/java/nio/file/FileSystem` | ` https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.nio.file.Path,%20java.util.Map<java.lang.String,?>)(https://developer.android.com/reference/java/nio/file/Path path, https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/String, ?> env) ` Constructs a new `FileSystem` to access the contents of a file as a file system. |
| ` static https://developer.android.com/reference/java/nio/file/FileSystem` | ` https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.nio.file.Path,%20java.lang.ClassLoader)(https://developer.android.com/reference/java/nio/file/Path path, https://developer.android.com/reference/java/lang/ClassLoader loader) ` Constructs a new `FileSystem` to access the contents of a file as a file system. |
| ` static https://developer.android.com/reference/java/nio/file/FileSystem` | ` https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.net.URI,%20java.util.Map<java.lang.String,?>,%20java.lang.ClassLoader)(https://developer.android.com/reference/java/net/URI uri, https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/String, ?> env, https://developer.android.com/reference/java/lang/ClassLoader loader) ` Constructs a new file system that is identified by a `https://developer.android.com/reference/java/net/URI` This method first attempts to locate an installed provider in exactly the same manner as the `https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.net.URI,%20java.util.Map<java.lang.String,?>)` method. |
| ` static https://developer.android.com/reference/java/nio/file/FileSystem` | ` https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.nio.file.Path)(https://developer.android.com/reference/java/nio/file/Path path) ` Constructs a new `FileSystem` to access the contents of a file as a file system. |
| ` static https://developer.android.com/reference/java/nio/file/FileSystem` | ` https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.nio.file.Path,%20java.util.Map<java.lang.String,?>,%20java.lang.ClassLoader)(https://developer.android.com/reference/java/nio/file/Path path, https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/String, ?> env, https://developer.android.com/reference/java/lang/ClassLoader loader) ` Constructs a new `FileSystem` to access the contents of a file as a file system. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public methods

### getDefault

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static FileSystem getDefault ()
```

Returns the default `FileSystem`. The default file system creates objects that provide access to the file systems accessible to the Java virtual machine. The *working directory* of the file system is the current user directory, named by the system property `user.dir`. This allows for interoperability with the `https://developer.android.com/reference/java/io/File` class.

The first invocation of any of the methods defined by this class locates the default `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider` object. Where the system property `java.nio.file.spi.DefaultFileSystemProvider` is not defined then the default provider is a system-default provider that is invoked to create the default file system.

If the system property `java.nio.file.spi.DefaultFileSystemProvider` is defined then it is taken to be a list of one or more fully-qualified names of concrete provider classes identified by the URI scheme `"file"`. Where the property is a list of more than one name then the names are separated by a comma. Each class is loaded, using the system class loader, and instantiated by invoking a one argument constructor whose formal parameter type is `FileSystemProvider`. The providers are loaded and instantiated in the order they are listed in the property. If this process fails or a provider's scheme is not equal to `"file"` then an unspecified error is thrown. URI schemes are normally compared without regard to case but for the default provider, the scheme is required to be `"file"`. The first provider class is instantiated by invoking it with a reference to the system-default provider. The second provider class is instantiated by invoking it with a reference to the first provider instance. The third provider class is instantiated by invoking it with a reference to the second instance, and so on. The last provider to be instantiated becomes the default provider; its `getFileSystem` method is invoked with the URI `"file:///"` to get a reference to the default file system.

Subsequent invocations of this method return the file system that was returned by the first invocation.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/nio/file/FileSystem` | the default file system <br /> |

### getFileSystem

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static FileSystem getFileSystem (URI uri)
```

Returns a reference to an existing `FileSystem`.

This method iterates over the `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#installedProviders()` providers to locate the provider that is identified by the URI `https://developer.android.com/reference/java/net/URI#getScheme()` of the given URI. URI schemes are compared without regard to case. The exact form of the URI is highly provider dependent. If found, the provider's `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#getFileSystem(java.net.URI)` method is invoked to obtain a reference to the `FileSystem`.

Once a file system created by this provider is `https://developer.android.com/reference/java/nio/file/FileSystem#close()` it is provider-dependent if this method returns a reference to the closed file system or throws `https://developer.android.com/reference/java/nio/file/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 `https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.net.URI,%20java.util.Map<java.lang.String,?>)` 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 `https://developer.android.com/reference/java/nio/file/FileSystems#getDefault()` file system, no permission check is required.

<br />

| Parameters ||
|---|---|
| `uri` | `URI`: the URI to locate the file system <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/nio/file/FileSystem` | the reference to the file system <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the pre-conditions for the `uri` parameter are not met |
| `https://developer.android.com/reference/java/lang/SecurityException` | if a security manager is installed and it denies an unspecified permission |
| `https://developer.android.com/reference/java/nio/file/FileSystemNotFoundException` | if the file system, identified by the URI, does not exist |
| `https://developer.android.com/reference/java/nio/file/ProviderNotFoundException` | if a provider supporting the URI scheme is not installed |

### newFileSystem

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static FileSystem newFileSystem (URI uri, 
                Map<String, ?> env)
```

Constructs a new file system that is identified by a `https://developer.android.com/reference/java/net/URI`

This method iterates over the `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#installedProviders()` providers to locate the provider that is identified by the URI `https://developer.android.com/reference/java/net/URI#getScheme()` of the given URI. URI schemes are compared without regard to case. The exact form of the URI is highly provider dependent. If found, the provider's `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#newFileSystem(java.net.URI,%20java.util.Map<java.lang.String,?>)` method is invoked to construct the new file system.

Once a file system is `https://developer.android.com/reference/java/nio/file/FileSystem#close()` 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.

**Usage Example:** Suppose there is a provider identified by the scheme `"memory"` installed:

```
 FileSystem fs = FileSystems.newFileSystem(URI.create("memory:///?name=logfs"),
                                           Map.of("capacity", "16G", "blockSize", "4k"));
```

<br />

<br />

| Parameters ||
|---|---|
| `uri` | `URI`: the URI identifying the file system <br /> |
| `env` | `Map`: a map of provider specific properties to configure the file system; may be empty <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/nio/file/FileSystem` | a new file system <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs creating the file system |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the pre-conditions for the `uri` parameter are not met, or the `env` parameter does not contain properties required by the provider, or a property value is invalid |
| `https://developer.android.com/reference/java/lang/SecurityException` | if a security manager is installed and it denies an unspecified permission required by the file system provider implementation |
| `https://developer.android.com/reference/java/nio/file/FileSystemAlreadyExistsException` | if the file system has already been created |
| `https://developer.android.com/reference/java/nio/file/ProviderNotFoundException` | if a provider supporting the URI scheme is not installed |

### newFileSystem

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static FileSystem newFileSystem (Path path, 
                Map<String, ?> env)
```

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

This method makes use of specialized providers that create pseudo file systems where the contents of one or more files is treated as a file system.

This method first attempts to locate an installed provider in exactly the same manner as the `https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.nio.file.Path,%20java.util.Map<java.lang.String,?>,%20java.lang.ClassLoader)` method. If found, the provider's `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#newFileSystem(java.nio.file.Path,%20java.util.Map<java.lang.String,?>)` method is invoked to construct the new file system.

<br />

| Parameters ||
|---|---|
| `path` | `Path`: the path to the file <br /> |
| `env` | `Map`: a map of provider specific properties to configure the file system; may be empty <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/nio/file/FileSystem` | a new file system <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs |
| `https://developer.android.com/reference/java/lang/SecurityException` | if a security manager is installed and it denies an unspecified permission |
| `https://developer.android.com/reference/java/nio/file/ProviderNotFoundException` | if a provider supporting this file type cannot be located |
| `https://developer.android.com/reference/java/util/ServiceConfigurationError` | when an error occurs while loading a service provider |

### newFileSystem

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static FileSystem newFileSystem (Path path, 
                ClassLoader loader)
```

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

This method makes use of specialized providers that create pseudo file systems where the contents of one or more files is treated as a file system.

This method first attempts to locate an installed provider in exactly the same manner as the `https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.nio.file.Path,%20java.util.Map<java.lang.String,?>,%20java.lang.ClassLoader)` method with an empty map. If none of the installed providers return a `FileSystem` then an attempt is made to locate the provider using the given class loader. If a provider returns a file system then the lookup terminates and the file system is returned.

<br />

| Parameters ||
|---|---|
| `path` | `Path`: the path to the file <br /> |
| `loader` | `ClassLoader`: the class loader to locate the provider or `null` to only attempt to locate an installed provider <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/nio/file/FileSystem` | a new file system <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs |
| `https://developer.android.com/reference/java/lang/SecurityException` | if a security manager is installed and it denies an unspecified permission |
| `https://developer.android.com/reference/java/nio/file/ProviderNotFoundException` | if a provider supporting this file type cannot be located |
| `https://developer.android.com/reference/java/util/ServiceConfigurationError` | when an error occurs while loading a service provider |

### newFileSystem

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static FileSystem newFileSystem (URI uri, 
                Map<String, ?> env, 
                ClassLoader loader)
```

Constructs a new file system that is identified by a `https://developer.android.com/reference/java/net/URI`

This method first attempts to locate an installed provider in exactly the same manner as the `https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.net.URI,%20java.util.Map<java.lang.String,?>)` method. If none of the installed providers support the URI scheme then an attempt is made to locate the provider using the given class loader. If a provider supporting the URI scheme is located then its `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#newFileSystem(java.net.URI,%20java.util.Map<java.lang.String,?>)` is invoked to construct the new file system.

<br />

| Parameters ||
|---|---|
| `uri` | `URI`: the URI identifying the file system <br /> |
| `env` | `Map`: a map of provider specific properties to configure the file system; may be empty <br /> |
| `loader` | `ClassLoader`: the class loader to locate the provider or `null` to only attempt to locate an installed provider <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/nio/file/FileSystem` | a new file system <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | an I/O error occurs creating the file system |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the pre-conditions for the `uri` parameter are not met, or the `env` parameter does not contain properties required by the provider, or a property value is invalid |
| `https://developer.android.com/reference/java/lang/SecurityException` | if a security manager is installed and it denies an unspecified permission required by the file system provider implementation |
| `https://developer.android.com/reference/java/nio/file/FileSystemAlreadyExistsException` | if the URI scheme identifies an installed provider and the file system has already been created |
| `https://developer.android.com/reference/java/nio/file/ProviderNotFoundException` | if a provider supporting the URI scheme is not found |
| `https://developer.android.com/reference/java/util/ServiceConfigurationError` | when an error occurs while loading a service provider |

### newFileSystem

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static FileSystem newFileSystem (Path path)
```

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

This method makes use of specialized providers that create pseudo file systems where the contents of one or more files is treated as a file system.

This method first attempts to locate an installed provider in exactly the same manner as the `https://developer.android.com/reference/java/nio/file/FileSystems#newFileSystem(java.nio.file.Path,%20java.util.Map<java.lang.String,?>,%20java.lang.ClassLoader)` method. If found, the provider's `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#newFileSystem(java.nio.file.Path,%20java.util.Map<java.lang.String,?>)` method is invoked with an empty map to construct the new file system.

<br />

| Parameters ||
|---|---|
| `path` | `Path`: the path to the file <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/nio/file/FileSystem` | a new file system <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs |
| `https://developer.android.com/reference/java/lang/SecurityException` | if a security manager is installed and it denies an unspecified permission |
| `https://developer.android.com/reference/java/nio/file/ProviderNotFoundException` | if a provider supporting this file type cannot be located |
| `https://developer.android.com/reference/java/util/ServiceConfigurationError` | when an error occurs while loading a service provider |

### newFileSystem

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static FileSystem newFileSystem (Path path, 
                Map<String, ?> env, 
                ClassLoader loader)
```

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

This method makes use of specialized providers that create pseudo file systems where the contents of one or more files is treated as a file system.

This method iterates over the `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#installedProviders()` providers. It invokes, in turn, each provider's `https://developer.android.com/reference/java/nio/file/spi/FileSystemProvider#newFileSystem(java.nio.file.Path,%20java.util.Map<java.lang.String,?>)` method. If a provider returns a file system then the iteration terminates and the file system is returned. If none of the installed providers return a `FileSystem` then an attempt is made to locate the provider using the given class loader. If a provider returns a file system, then the lookup terminates and the file system is returned.

<br />

| Parameters ||
|---|---|
| `path` | `Path`: the path to the file <br /> |
| `env` | `Map`: a map of provider specific properties to configure the file system; may be empty <br /> |
| `loader` | `ClassLoader`: the class loader to locate the provider or `null` to only attempt to locate an installed provider <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/nio/file/FileSystem` | a new file system <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs |
| `https://developer.android.com/reference/java/lang/SecurityException` | if a security manager is installed and it denies an unspecified permission |
| `https://developer.android.com/reference/java/nio/file/ProviderNotFoundException` | if a provider supporting this file type cannot be located |
| `https://developer.android.com/reference/java/util/ServiceConfigurationError` | when an error occurs while loading a service provider |