https://kotlinlang.org logo
#getting-started
Title
# getting-started
c

CamilleBC

10/12/2018, 9:09 AM
Hello! Just a quick question: if I want to use a Kotlin File() with a PrintWriter, should I close it afterwards? The dev guide doesn't bother to do so (https://developer.android.com/training/data-storage/files). Here is what I have:
Copy code
fun writeToLog(s: String) {
        val logFile = File(c.filesDir, FILENAME)
        logFile.printWriter().use {
            it.print(s)
            it.close()
        }
    }
Is the close() unnecessary?
🚫 1