Use Source.fromResource instead of Source.fromFile if you are using scala 2.12.
Example:
If you put the file in public folder, don't use the leading slash.
Source.fromResource(“public/files/abc.txt”)
If you put the file in conf folder, don't include conf in the path.
Source.fromResource(“files/abc.txt”) // conf/files/abc.txt
If you are using scala < 2.12, you can fall back to Java. There are 2 ways.
Relative path(no leading slash)
scala.io.Source.fromInputStream(getClass.getClassLoader.getResourceAsStream(“public/test.txt”))
Absolute path (leading slash required)
scala.io.Source.fromInputStream(getClass.getResourceAsStream(“/public/test.txt”))
I guess you also have to exclude "conf" in the path if you put the file in conf folder.
Lastly, you can learn how Java's resource loading works in this blog.