How to check if path or file exist in Scala

前端 未结 4 1015
北荒
北荒 2020-12-05 22:47

How do I check if a path / file exists in Scala similar to Python ? An example below:

os.path.exists(\"/home\")
Out[4]: True
4条回答
  •  醉梦人生
    2020-12-05 23:09

    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
    

提交回复
热议问题