Java: File.getAbsoluteFile (). exists () v / s File.exists ()
First of all read the Oracle docs on exists . And getAbsoluteFile .
Answer yourself, what does it do getAbsoluteFile
? Then answer yourself: do you need to get the absolute form of the abstract path of your folder? Does it help you with anything?
If not, use the easiest, easiest-to-read reading method folder.exists()
.
In coding, we always try not to do anything fancy to keep our code fast, clean, readable, easy to understand and update.
source to share
You can also use both conditions.
Additionally you can refer to this link ..
How do I create a file - including folders - for a given path?
Hope this helps!
source to share
folder.exist()
check if the directory exists in the abstract path, it returns true if and only if the file or directory denoted by this abstract path exists; false otherwise.
folder.getAbsoluteFile().exists()
in this case, returns the absolute form of this abstract path. Equivalent to new File(this.getAbsolutePath()).exist()
and checks if the folder at the specified absolute path exists.
so you can use either of them, just the difference is an abstract path and an absolute path, but to my discovery you have to go with folder.exist()
since this will avoid creation new File
.
source to share