How do I check if a path / file exists in Scala similar to Python ? An example below:
os.path.exists("/home") Out[4]: True
Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).
A file path describes the location of a file in a web site's folder structure. File paths are used when linking to external files, like: Web pages. Images.
To check if a string represents a path or a file programatically, you should use API methods such as isFile(), isDirectory().
A path is a slash-separated list of directory names followed by either a directory name or a file name. A directory is the same as a folder.
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
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