Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current (working) directory in Scala?

How can I get the current directory (working directory) of the executing program in Scala?

like image 290
Neil Avatar asked Apr 16 '18 14:04

Neil


People also ask

How to check working directory in spark?

In SparkR, the default working directory is "/usr/hdp/2.4. 0.0-169/spark".

How do you get CWD in Golang?

Getwd functionis used to get the current working directory in Golang, the function returns the rooted path name and if the current directory can be reached via multiple paths, the function can return any one of them.


1 Answers

Use java.nio:

import java.nio.file.Paths
println(Paths.get(".").toAbsolutePath)

Remark on scala.reflect.io.File: I don't see any reason to look into scala.reflect packages for such mundane tasks. Getting the current working directory has usually nothing to do with Scala's reflection capabilities. Here are more reasons not to use scala.reflect.io.File: link.

like image 179
Andrey Tyukin Avatar answered Oct 25 '22 19:10

Andrey Tyukin