File isAbsolute() method in Java with Examples
The isAbsolute() method is a part of File class. The function returns whether the abstract pathname is absolute or not.
For Example: if we create a file object using the path as “program.txt”, it points to the file present in the same directory where the executable program is kept (if you are using a IDE it will point to the file where you have saved the program ). Here the path of the file mentioned above is “program.txt” but this path is not absolute (i.e. not complete) .Absolute path is the complete path from the root directory.
public boolean isAbsolute()
Parameters: This function does not accept any parameters.
Return value: The function returns boolean value which tells whether the abstract pathname is absolute or not.
Below programs will illustrate the use of the isAbsolute() function
Example 1: We are given a file object of a file, we have to check whether it is absolute or not
The path is absolute
Example 2: We are given a file object of a file, we have to check whether it is absolute or not
The path is not absolute
The programs might not run in an online IDE. please use an offline IDE and set the Parent file of the file
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.