I am trying to access a file in Scala using io.Source.fromfile
.
I have specified the full path, but i am still getting a no such directory or file
error.
This is a general version of what my code looks like:
val lines = io.Source.fromFile("~/top/next/source/resources/desiredFile.txt").getLines()
I'm running Ubuntu if that makes any difference.
It probably because you are using tilde sign, use full absolute path. If you want to avoid hard coding your home directory, you can get it from environment variables:
val home = System.getProperty("user.home")
val s = Source.fromFile(s"${home}/.....").getLines()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With