FileSystem

sealed interface FileSystem(source)

An interface providing basic operations on a filesystem, such as reading and writing files, creating directories, gathering file metadata and so on.

Default implementation of this interface is SystemFileSystem. It provides access to files and directories on disk.

The interface is sealed until API stabilization, but in the future it will allow creating custom filesystems that could be used as mocks for testing or provide access to some network resources and allow working with them as with regular files, for example.

This API is unstable and subject to change.

Functions

Link copied to clipboard
abstract fun atomicMove(source: Path, destination: Path)

Atomically renames source to destination overriding destination if it already exists.

Link copied to clipboard
abstract fun createDirectories(path: Path, mustCreate: Boolean = false)

Creates a directory tree represented by the path. If path already exists then the method throws kotlinx.io.IOException when mustCreate is true. The call will attempt to create only missing directories. The method is not atomic and if it fails after creating some directories, these directories will not be deleted automatically. Permissions for created directories are platform-specific.

Link copied to clipboard
abstract fun delete(path: Path, mustExist: Boolean = true)

Deletes a file or directory the path points to from a filesystem. If there is no filesystem entity represented by the path this method throws kotlinx.io.files.FileNotFoundException when mustExist is true.

Link copied to clipboard
abstract fun exists(path: Path): Boolean

Returns true if there is a filesystem entity a path points to, otherwise returns false.

Link copied to clipboard
abstract fun metadataOrNull(path: Path): FileMetadata?

Return FileMetadata associated with a file or directory the path points to. If there is no such file or directory, or it's impossible to fetch metadata, null is returned.

Link copied to clipboard
abstract fun resolve(path: Path): Path

Returns an absolute path to the same file or directory the path is pointing to. All symbolic links are solved, extra path separators and references to current (.) or parent (..) directories are removed. If the path is a relative path then it'll be resolved against current working directory. If there is no file or directory to which the path is pointing to then FileNotFoundException will be thrown.

Link copied to clipboard
abstract fun sink(path: Path, append: Boolean = false): RawSink

Returns RawSink to write into a file the path points to. Depending on append value, the file will be overwritten or data will be appened to it. File will be created if it does not exist yet.

Link copied to clipboard
abstract fun source(path: Path): RawSource

Returns RawSource to read from a file the path points to.