Package kotlin.io

IO API for working with files and streams.

Types

JVM
1.0

FileTreeWalk

This class is intended to implement different file traversal methods. It allows to iterate through all files inside a given directory.

class FileTreeWalk : Sequence<File>
JVM
1.0

FileWalkDirection

An enumeration to describe possible walk directions. There are two of them: beginning from parents, ending with children, and beginning from children, ending with parents. Both use depth-first search.

enum class FileWalkDirection
JVM
1.0

OnErrorAction

Enum that can be used to specify behaviour of the copyRecursively() function in exceptional conditions.

enum class OnErrorAction

Exceptions

JVM
1.0

AccessDeniedException

An exception class which is used when we have not enough access for some operation.

class AccessDeniedException : FileSystemException
JVM
1.0

FileAlreadyExistsException

An exception class which is used when some file to create or copy to already exists.

class FileAlreadyExistsException : FileSystemException
JVM
1.0

FileSystemException

A base exception class for file system exceptions.

open class FileSystemException : IOException
JVM
1.0

NoSuchFileException

An exception class which is used when file to copy does not exist.

class NoSuchFileException : FileSystemException

Extensions for External Classes

Properties

JVM
1.0

DEFAULT_BUFFER_SIZE

Returns the default buffer size when working with buffered streams.

const val DEFAULT_BUFFER_SIZE: Int

Functions

JVM
1.0

byteInputStream

Creates a new byte input stream for the string.

fun String.byteInputStream(
    charset: Charset = Charsets.UTF_8
): ByteArrayInputStream
JVM
1.0

createTempDir

Creates an empty directory in the specified directory, using the given prefix and suffix to generate its name.

fun createTempDir(
    prefix: String = "tmp",
    suffix: String? = null,
    directory: File? = null
): File
JVM
1.0

createTempFile

Creates a new empty file in the specified directory, using the given prefix and suffix to generate its name.

fun createTempFile(
    prefix: String = "tmp",
    suffix: String? = null,
    directory: File? = null
): File
JVM
1.0

inputStream

Creates an input stream for reading data from this byte array.

fun ByteArray.inputStream(): ByteArrayInputStream

Creates an input stream for reading data from the specified portion of this byte array.

fun ByteArray.inputStream(
    offset: Int,
    length: Int
): ByteArrayInputStream

print

Prints the given message to the standard output stream.

JVM
1.0
fun print(message: Int)
JVM
1.0
fun print(message: Long)
JVM
1.0
fun print(message: Byte)
JVM
1.0
fun print(message: Short)
JVM
1.0
fun print(message: Char)
JVM
1.0
fun print(message: Boolean)
JVM
1.0
fun print(message: Float)
JVM
1.0
fun print(message: Double)
JVM
1.0
fun print(message: CharArray)
Common
JVM
JS
Native
1.0
fun print(message: Any?)

println

Prints the given message and the line separator to the standard output stream.

JVM
1.0
fun println(message: Int)
JVM
1.0
fun println(message: Long)
JVM
1.0
fun println(message: Byte)
JVM
1.0
fun println(message: Short)
JVM
1.0
fun println(message: Char)
JVM
1.0
fun println(message: Boolean)
JVM
1.0
fun println(message: Float)
JVM
1.0
fun println(message: Double)
JVM
1.0
fun println(message: CharArray)
Common
JVM
JS
Native
1.0
fun println(message: Any?)

Prints the line separator to the standard output stream.

Common
JVM
JS
Native
1.0
fun println()
JVM
1.0

reader

Creates a new reader for the string.

fun String.reader(): StringReader
JVM
Native
1.0

readLine

Reads a line of input from the standard input stream.

fun readLine(): String?
Common
JVM
JS
Native
1.6

readln

Reads a line of input from the standard input stream and returns it, or throws a RuntimeException if EOF has already been reached when readln is called.

fun readln(): String
Common
JVM
JS
Native
1.6

readlnOrNull

Reads a line of input from the standard input stream and returns it, or return null if EOF has already been reached when readlnOrNull is called.

fun readlnOrNull(): String?
JVM
1.0

use

Executes the given block function on this resource and then closes it down correctly whether an exception is thrown or not.

fun <T : Closeable?, R> T.use(block: (T) -> R): R