Extensions for java.io.File
bufferedReader
Returns a new BufferedReader for reading the content of this file.
fun File.bufferedReader(
charset: Charset = Charsets.UTF_8,
bufferSize: Int = DEFAULT_BUFFER_SIZE
): BufferedReader
bufferedWriter
Returns a new BufferedWriter for writing the content of this file.
fun File.bufferedWriter(
charset: Charset = Charsets.UTF_8,
bufferSize: Int = DEFAULT_BUFFER_SIZE
): BufferedWriter
copyRecursively
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.copyRecursively(
target: File,
overwrite: Boolean = false,
onError: (File, IOException) -> OnErrorAction = { _, exception -> throw exception }
): Boolean
deleteRecursively
Delete this file with all its children. Note that if this operation fails then partial deletion may have taken place.
fun File.deleteRecursively(): Boolean
extension
Returns the extension of this file (not including the dot), or an empty string if it doesn't have one.
val File.extension: String
forEachBlock
inputStream
Constructs a new FileInputStream of this file and returns it as a result.
fun File.inputStream(): FileInputStream
isRooted
Determines whether this file has a root or it represents a relative path.
val File.isRooted: Boolean
nameWithoutExtension
Returns file's name without an extension.
val File.nameWithoutExtension: String
outputStream
Constructs a new FileOutputStream of this file and returns it as a result.
fun File.outputStream(): FileOutputStream
printWriter
Returns a new PrintWriter for writing the content of this file.
fun File.printWriter(
charset: Charset = Charsets.UTF_8
): PrintWriter
reader
Returns a new FileReader for reading the content of this file.
fun File.reader(
charset: Charset = Charsets.UTF_8
): InputStreamReader
resolve
Adds relative file to this, considering this as a directory.
If relative has a root, relative is returned back.
For instance, File("/foo/bar").resolve(File("gav"))
is File("/foo/bar/gav")
.
This function is complementary with relativeTo,
so f.resolve(g.relativeTo(f)) == g
should be always true
except for different roots case.
resolveSibling
walk
Gets a sequence for visiting this directory and all its content.
fun File.walk(
direction: FileWalkDirection = FileWalkDirection.TOP_DOWN
): FileTreeWalk
walkBottomUp
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.walkBottomUp(): FileTreeWalk
walkTopDown
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.walkTopDown(): FileTreeWalk
writer
Returns a new FileWriter for writing the content of this file.
fun File.writer(
charset: Charset = Charsets.UTF_8
): OutputStreamWriter