All Downloads are FREE. Search and download functionalities are using the official Maven repository.

name.remal.java.util.Properties.kt Maven / Gradle / Ivy

package name.remal

import java.io.File
import java.io.StringWriter
import java.util.*
import kotlin.text.Charsets.UTF_8

fun loadProperties(file: File) = Properties().apply { load(file) }

fun Properties.load(file: File) {
    file.inputStream().use { load(it) }
}

fun Properties.store(file: File, doStripComments: Boolean = true) {
    var content = StringWriter().use { store(it, ""); it.toString() }
    if (doStripComments) {
        content = content.splitToSequence('\n')
            .map { it.substringBefore('#').trim() }
            .filter(String::isNotEmpty)
            .joinToString("\n")
    }
    file.writeText(content, UTF_8)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy