kotlin.io.java.io.File
Extensions for java.io.File
fun File.appendBytes(array: ByteArray) Appends an array of bytes to the content of this file. | |
fun File.appendText( text: String, charset: Charset = Charsets.UTF_8) Appends text to the content of this file using UTF-8 or the specified charset. | |
fun File.bufferedReader( charset: Charset = Charsets.UTF_8, bufferSize: Int = DEFAULT_BUFFER_SIZE ): BufferedReader Returns a new BufferedReader for reading the content of this file. | |
fun File.bufferedWriter( charset: Charset = Charsets.UTF_8, bufferSize: Int = DEFAULT_BUFFER_SIZE ): BufferedWriter Returns a new BufferedWriter for writing the content of this file. | |
fun File.copyRecursively( target: File, overwrite: Boolean = false, onError: (File, IOException) -> OnErrorAction = { file, exception -> throw exception } ): Boolean Copies this file with all its children to the specified destination target path. If some directories on the way to the destination are missing, then they will be created. | |
fun File.copyTo( target: File, overwrite: Boolean = false, bufferSize: Int = DEFAULT_BUFFER_SIZE ): File Copies this file to the given target file. | |
fun File.deleteRecursively(): Boolean Delete this file with all its children. Note that if this operation fails then partial deletion may have taken place. | |
fun File.endsWith(other: File): Boolean Determines whether this file path ends with the path of other file. fun File.endsWith(other: String): Boolean Determines whether this file belongs to the same root as other and ends with all components of other in the same order. So if other has N components, last N components of | |
val File.extension: String Returns the extension of this file (not including the dot), or an empty string if it doesn't have one. | |
fun File.forEachBlock( action: (buffer: ByteArray, bytesRead: Int) -> Unit) Reads file by byte blocks and calls action for each block read. Block has default size which is implementation-dependent. This functions passes the byte array and amount of bytes in the array to the action function. fun File.forEachBlock( blockSize: Int, action: (buffer: ByteArray, bytesRead: Int) -> Unit) Reads file by byte blocks and calls action for each block read. This functions passes the byte array and amount of bytes in the array to the action function. | |
fun File.forEachLine( charset: Charset = Charsets.UTF_8, action: (line: String) -> Unit) Reads this file line by line using the specified charset and calls action for each line. Default charset is UTF-8. | |
fun File.inputStream(): FileInputStream Constructs a new FileInputStream of this file and returns it as a result. | |
val File.invariantSeparatorsPath: String Returns path of this File using the invariant separator '/' to separate the names in the name sequence. | |
val File.isRooted: Boolean Determines whether this file has a root or it represents a relative path. | |
val File.nameWithoutExtension: String Returns file's name without an extension. | |
fun File.normalize(): File Removes all . and resolves all possible .. in this file name. For instance, | |
fun File.outputStream(): FileOutputStream Constructs a new FileOutputStream of this file and returns it as a result. | |
fun File.printWriter( charset: Charset = Charsets.UTF_8 ): PrintWriter Returns a new PrintWriter for writing the content of this file. | |
fun File.readBytes(): ByteArray Gets the entire content of this file as a byte array. | |
fun File.readLines( charset: Charset = Charsets.UTF_8 ): List<String> Reads the file content as a list of lines. | |
fun File.readText(charset: Charset = Charsets.UTF_8): String Gets the entire content of this file as a String using UTF-8 or specified charset. | |
fun File.reader( charset: Charset = Charsets.UTF_8 ): InputStreamReader Returns a new FileReader for reading the content of this file. | |
fun File.relativeTo(base: File): File Calculates the relative path for this file from base file. Note that the base file is treated as a directory. If this file matches the base file, then a File with empty path will be returned. | |
fun File.relativeToOrNull(base: File): File? Calculates the relative path for this file from base file. Note that the base file is treated as a directory. If this file matches the base file, then a File with empty path will be returned. | |
fun File.relativeToOrSelf(base: File): File Calculates the relative path for this file from base file. Note that the base file is treated as a directory. If this file matches the base file, then a File with empty path will be returned. | |
fun File.resolve(relative: File): File Adds relative file to this, considering this as a directory. If relative has a root, relative is returned back. For instance, fun File.resolve(relative: String): File Adds relative name to this, considering this as a directory. If relative has a root, relative is returned back. For instance, | |
fun File.resolveSibling(relative: File): File Adds relative file to this parent directory. If relative has a root or this has no parent directory, relative is returned back. For instance, fun File.resolveSibling(relative: String): File Adds relative name to this parent directory. If relative has a root or this has no parent directory, relative is returned back. For instance, | |
fun File.startsWith(other: File): Boolean fun File.startsWith(other: String): Boolean Determines whether this file belongs to the same root as other and starts with all components of other in the same order. So if other has N components, first N components of | |
fun File.toRelativeString(base: File): String Calculates the relative path for this file from base file. Note that the base file is treated as a directory. If this file matches the base file, then an empty string will be returned. | |
fun <T> File.useLines( charset: Charset = Charsets.UTF_8, block: (Sequence<String>) -> T ): T Calls the block callback giving it a sequence of all the lines in this file and closes the reader once the processing is complete. | |
fun File.walk( direction: FileWalkDirection = FileWalkDirection.TOP_DOWN ): FileTreeWalk Gets a sequence for visiting this directory and all its content. | |
fun File.walkBottomUp(): FileTreeWalk Gets a sequence for visiting this directory and all its content in bottom-up order. Depth-first search is used and directories are visited after all their files. | |
fun File.walkTopDown(): FileTreeWalk Gets a sequence for visiting this directory and all its content in top-down order. Depth-first search is used and directories are visited before all their files. | |
fun File.writeBytes(array: ByteArray) Sets the content of this file as an array of bytes. If this file already exists, it becomes overwritten. | |
fun File.writeText( text: String, charset: Charset = Charsets.UTF_8) Sets the content of this file as text encoded using UTF-8 or specified charset. If this file exists, it becomes overwritten. | |
fun File.writer( charset: Charset = Charsets.UTF_8 ): OutputStreamWriter Returns a new FileWriter for writing the content of this file. |
© 2010–2017 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/java.io.-file/