# FileStorage

Artifact: [androidx.datastore:datastore-core](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/core/FileStorage.kt+class:androidx.datastore.core.FileStorage) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.1.0)

*** ** * ** ***


```
public final class FileStorage<T extends Object> implements Storage<@NonNull T>
```

<br />

*** ** * ** ***

The Java IO File version of the Storage interface. Is able to read and write `https://developer.android.com/reference/androidx/datastore/core/FileStorage` to a given file location.

## Summary

| ### Public constructors |
|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/datastore/core/FileStorage#FileStorage(androidx.datastore.core.Serializer,kotlin.Function1,kotlin.Function0)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/core/Serializer<@https://developer.android.com/reference/androidx/annotation/NonNull T> serializer, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/File.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/core/InterProcessCoordinator> coordinatorProducer, @https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/File.html> produceFile )` |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/core/StorageConnection<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/datastore/core/FileStorage#createConnection()()` Creates a storage connection which allows reading and writing to the underlying storage. |

## Public constructors

### FileStorage

```
public <T extends Object> FileStorage(
    @NonNull Serializer<@NonNull T> serializer,
    @NonNull Function1<@NonNull File, @NonNull InterProcessCoordinator> coordinatorProducer,
    @NonNull Function0<@NonNull File> produceFile
)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/core/Serializer<@https://developer.android.com/reference/androidx/annotation/NonNull T> serializer` | The serializer that can write `https://developer.android.com/reference/androidx/datastore/core/FileStorage` to and from a byte array. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/File.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/datastore/core/InterProcessCoordinator> coordinatorProducer` | The producer to provide `https://developer.android.com/reference/androidx/datastore/core/InterProcessCoordinator` that coordinates IO operations across processes if needed. By default it provides single process coordinator, which doesn't support cross process use cases. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/File.html> produceFile` | The file producer that returns the file that will be read and written. |

## Public methods

### createConnection

```
public @NonNull StorageConnection<@NonNull T> createConnection()
```

Creates a storage connection which allows reading and writing to the underlying storage.

Should be closed after usage.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/datastore/core/IOException` | Unrecoverable IO exception when trying to access the underlying storage. |