How to read a file from classpath without external dependencies?

val text = io.Source.fromInputStream(getClass.getResourceAsStream("file.xml")).mkString

If you want to ensure that the file is closed:

val source = io.Source.fromInputStream(getClass.getResourceAsStream("file.xml"))
val text = try source.mkString finally source.close()

Leave a Comment