How do I check if a path / file exists in Scala similar to Python ? An example below:
os.path.exists("/home") Out[4]: True
How do I check if a path / file exists in Scala similar to Python ? An example below:
os.path.exists("/home") Out[4]: True
Since Java 7 the better way would be
scala> import java.nio.file.{Paths, Files} import java.nio.file.{Paths, Files} scala> Files.exists(Paths.get("/tmp")) res0: Boolean = true
Well, sorry I found the answer to my own question:
scala> new java.io.File("/tmp").exists res0: Boolean = true
you can use scala library as well :
scala.reflect.io.File(scala.reflect.io.Path("<actual file path>")).exists