Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala io.Source.fromfile not finding my file even with absolute path specified

Tags:

io

file-io

scala

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.

like image 358
redeagle47 Avatar asked Sep 20 '25 02:09

redeagle47


1 Answers

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() 
like image 53
grotrianster Avatar answered Sep 23 '25 05:09

grotrianster