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

com.github.leandroborgesferreira.dagcommand.output.Files.kt Maven / Gradle / Ivy

There is a newer version: 1.7.0
Show newest version
package com.github.leandroborgesferreira.dagcommand.output

import java.io.BufferedWriter
import java.io.File

fun writeToFile(directory: File, fileName: String, content: Iterable) {
    createFileBuffer(directory, fileName).use { writer ->
        content.forEach { line ->
            writer.write(line)
            writer.newLine()
        }
    }
}

fun writeToFile(directory: File, fileName: String, content: String) {
    createFileBuffer(directory, fileName).use { writer ->
        writer.write(content)
    }
}

private fun createFileBuffer(directory: File, fileName: String): BufferedWriter {
    if (!directory.exists()) directory.mkdirs()

    return File(directory.path, fileName)
        .outputStream()
        .bufferedWriter()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy