I would recommend using isFile()
instead of exists()
. Most of the time you are looking to check if the path points to a file not only that it exists. Remember that exists()
will return true if your path points to a directory.
new File("path/to/file.txt").isFile();
new File("C:/").exists()
will return true but will not allow you to open and read from it as a file.