Use Source.fromResource instead of Source.fromFile if you are using scala 2.12.
Example:
If you put the file in a shared folder, do not use the initial slash.
Source.fromResource("public/files/abc.txt")
If you put the file in the conf folder, do not include conf in the path.
Source.fromResource("files/abc.txt")
If you use scala <2.12, you can return to Java. There are 2 ways.
Relative path (no slash)
scala.io.Source.fromInputStream(getClass.getClassLoader.getResourceAsStream("public/test.txt"))
Absolute path (requires an initial slash)
scala.io.Source.fromInputStream(getClass.getResourceAsStream("/public/test.txt"))
I think you should also exclude "conf" in the path if you put the file in the conf folder.
Finally, you can find out how loading Java resources on this blog works.
source share