# 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)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- android

  ```
  class FileStorage<T : Any?> : Storage<T>
  ```

*** ** * ** ***

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

## Summary

| ### Public constructors |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/datastore/core/FileStorage#FileStorage(androidx.datastore.core.Serializer,kotlin.Function1,kotlin.Function0)( serializer: https://developer.android.com/reference/kotlin/androidx/datastore/core/Serializer<T>, coordinatorProducer: (https://developer.android.com/reference/java/io/File.html) -> https://developer.android.com/reference/kotlin/androidx/datastore/core/InterProcessCoordinator, produceFile: () -> https://developer.android.com/reference/java/io/File.html )` | android |

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

## Public constructors

### FileStorage

android

```
<T : Any?> FileStorage(
    serializer: Serializer<T>,
    coordinatorProducer: (File) -> InterProcessCoordinator = {
        createSingleProcessCoordinator(it)
    },
    produceFile: () -> File
)
```

| Parameters |
|---|---|
| `serializer: https://developer.android.com/reference/kotlin/androidx/datastore/core/Serializer<T>` | The serializer that can write `https://developer.android.com/reference/kotlin/androidx/datastore/core/FileStorage` to and from a byte array. |
| `coordinatorProducer: (https://developer.android.com/reference/java/io/File.html) -> https://developer.android.com/reference/kotlin/androidx/datastore/core/InterProcessCoordinator = { createSingleProcessCoordinator(it) }` | The producer to provide `https://developer.android.com/reference/kotlin/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. |
| `produceFile: () -> https://developer.android.com/reference/java/io/File.html` | The file producer that returns the file that will be read and written. |

## Public functions

### createConnection

android

```
open fun createConnection(): StorageConnection<T>
```

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

Should be closed after usage.

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