Kommons IO is a Kotlin Library for simpler IO handling on the JVM.
This library is hosted on GitHub with releases provided on Maven Central.
-
Gradle
implementation("com.bkahlert.kommons:kommons-io:2.8.0") { because("print debugging") }
-
Maven
<dependency> <groupId>com.bkahlert.kommons</groupId> <artifactId>kommons-io</artifactId> <version>2.8.0</version> </dependency>
Create files with contents in one call using
createTextFile
createBinaryFile
createTempTextFile
createTempBinaryFile
Read files with
useInputStream
,useBufferedInputStream
,useReader
, anduseBufferedReader
Write files with
useOutputStream
,useBufferedOutputStream
,useWriter
, anduseBufferedWriter
Find the class directory, the source directory or the source file itself of a class.
Foo::class.findClassesDirectoryOrNull() // /home/john/dev/project/build/classes/kotlin/jvm/test
Foo::class.findSourceDirectoryOrNull() // /home/john/dev/project/src/jvmTest/kotlin
Foo::class.findSourceFileOrNull() // /home/john/dev/project/src/jvmTest/kotlin/packages/source.kt
Access class path resources like any other NIO 2 path using the classpath
URI scheme.
Paths.get("classpath:dir/to/resource").readText()
Paths.get("classpath:dir/to/resource").readBytes()
Paths.get("classpath:dir/to/resource").copyToDirectory(SystemLocations.Temp)
Paths.get("classpath:dir/to/resource").useBufferedReader { it.readLine() }
Want to contribute? Awesome! The most basic way to show your support is to star the project or to raise issues. You can also support this project by making a PayPal donation to ensure this journey continues indefinitely!
Thanks again for your support, it's much appreciated! 🙏
MIT. See LICENSE for more details.