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
): BufferedReaderbufferedWriter
Returns a new BufferedWriter for writing the content of this file.
fun File.bufferedWriter(
charset: Charset = Charsets.UTF_8,
bufferSize: Int = DEFAULT_BUFFER_SIZE
): BufferedWritercopyRecursively
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 }
): BooleandeleteRecursively
Delete this file with all its children. Note that if this operation fails then partial deletion may have taken place.
fun File.deleteRecursively(): Booleanextension
Returns the extension of this file (not including the dot), or an empty string if it doesn't have one.
val File.extension: StringforEachBlock
inputStream
Constructs a new FileInputStream of this file and returns it as a result.
fun File.inputStream(): FileInputStreamisRooted
Determines whether this file has a root or it represents a relative path.
val File.isRooted: BooleannameWithoutExtension
Returns file's name without an extension.
val File.nameWithoutExtension: StringoutputStream
Constructs a new FileOutputStream of this file and returns it as a result.
fun File.outputStream(): FileOutputStreamprintWriter
Returns a new PrintWriter for writing the content of this file.
fun File.printWriter(
charset: Charset = Charsets.UTF_8
): PrintWriterreader
Returns a new FileReader for reading the content of this file.
fun File.reader(
charset: Charset = Charsets.UTF_8
): InputStreamReaderresolve
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
): FileTreeWalkwalkBottomUp
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(): FileTreeWalkwalkTopDown
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(): FileTreeWalkwriter
Returns a new FileWriter for writing the content of this file.
fun File.writer(
charset: Charset = Charsets.UTF_8
): OutputStreamWriter