theshell.ch/bonus2/src/ch/usi/inf/atelier/group1/util/extensions/File.kt
bevilj 4b9169460b bonus2: complete bonus 2
git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@167 a672b425-5310-4d7a-af5c-997e18724b81
2018-11-13 22:16:49 +00:00

33 lines
729 B
Kotlin

/*
* Copyright (c) 2018 Bevilacqua Joey.
*/
package ch.usi.inf.atelier.group1.util.extensions
import ch.usi.inf.atelier.group1.util.Log
import java.io.BufferedReader
import java.io.File
import java.io.FileReader
import java.io.IOException
/**
* Get the content of the file as String
*
* @return this File content
*/
fun File.getContent(): String {
val content = StringBuilder()
try {
val reader = BufferedReader(FileReader(this))
var line: String? = ""
while (line != null) {
content.append(line)
.append('\n')
line = reader.readLine()
}
} catch (e: IOException) {
Log.e(exception = e)
}
return content.toString()
}