2019-12-06 22:10:37 +01:00
|
|
|
package kamlib
|
|
|
|
|
|
|
|
import scala.io.Source
|
|
|
|
|
|
|
|
/** File IO helper */
|
|
|
|
object Reader {
|
|
|
|
|
|
|
|
/** Read file with the name specified in parameter */
|
|
|
|
def readList(filename: String): List[String] =
|
|
|
|
{
|
2019-12-06 22:43:55 +01:00
|
|
|
val src = Source.fromFile(getClass.getResource(filename).getFile)
|
2019-12-06 22:10:37 +01:00
|
|
|
val list = src.getLines().toList
|
|
|
|
src.close()
|
|
|
|
list
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Read file with the name specified in parameter */
|
|
|
|
def readArray(filename: String): Array[String] =
|
|
|
|
{
|
2019-12-06 22:43:55 +01:00
|
|
|
val src = Source.fromFile(getClass.getResource(filename).getFile)
|
2019-12-06 22:10:37 +01:00
|
|
|
val array = src.getLines().toArray
|
|
|
|
src.close()
|
|
|
|
array
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Read file with the name specified in parameter */
|
|
|
|
def readString(filename: String): String =
|
|
|
|
{
|
2019-12-06 22:43:55 +01:00
|
|
|
val src = Source.fromFile(getClass.getResource(filename).getFile)
|
2019-12-06 22:10:37 +01:00
|
|
|
val string = src.getLines().mkString
|
|
|
|
src.close()
|
|
|
|
string
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|