W3cubDocs

/Kotlin

Package kotlin.io

IO API for working with files and streams.

Types

FileTreeWalk

class FileTreeWalk : Sequence<File>

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

FileWalkDirection

enum class 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.

OnErrorAction

enum class OnErrorAction

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

Exceptions

AccessDeniedException

class AccessDeniedException : FileSystemException

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

FileAlreadyExistsException

class FileAlreadyExistsException : FileSystemException

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

FileSystemException

open class FileSystemException : IOException

A base exception class for file system exceptions.

NoSuchFileException

class NoSuchFileException : FileSystemException

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

Extensions for External Classes

java.io.BufferedInputStream

java.io.BufferedReader

java.io.File

java.io.InputStream

java.io.OutputStream

java.io.Reader

java.io.Writer

java.net.URL

Properties

DEFAULT_BUFFER_SIZE

const val DEFAULT_BUFFER_SIZE: Int

Returns the default buffer size when working with buffered streams.

Functions

byteInputStream

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

Creates a new byte input stream for the string.

createTempDir

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

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

createTempFile

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

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

inputStream

fun ByteArray.inputStream(): ByteArrayInputStream

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

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

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

print

fun print(message: Any?)
fun print(message: Int)
fun print(message: Long)
fun print(message: Byte)
fun print(message: Short)
fun print(message: Char)
fun print(message: Boolean)
fun print(message: Float)
fun print(message: Double)
fun print(message: CharArray)

Prints the given message to the standard output stream.

println

fun println(message: Any?)
fun println(message: Int)
fun println(message: Long)
fun println(message: Byte)
fun println(message: Short)
fun println(message: Char)
fun println(message: Boolean)
fun println(message: Float)
fun println(message: Double)
fun println(message: CharArray)

Prints the given message and newline to the standard output stream.

fun println()

Prints a newline to the standard output stream.

readLine

fun readLine(): String?

Reads a line of input from the standard input stream.

reader

fun String.reader(): StringReader

Creates a new reader for the string.

use

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

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

© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/