Path isAbsolute() method in Java with Examples
The Java Path interface was added to Java NIO in Java 7. isAbsolute() method of java.nio.file.Path used to check this path is absolute or not. This method return true if, and only if, this path is absolute. An absolute path is a path that doesn’t need to be combined with other path information in order to locate a file.
Syntax:
boolean isAbsolute()
Parameters: This method accepts nothing.
Return value: This method returns true if, and only if, this path is absolute.
Below programs illustrate isAbsolute() method:
Program 1:
// Java program to demonstrate // java.nio.file.Path.isAbsolute() method import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; public class GFG { public static void main(String[] args) throws IOException { // create an object of Path Path path = Paths.get("D:\\eclipse\\configuration" + "\\org.eclipse.update"); // call isAbsolute() to get check // path is absolute or not boolean isAbsolute = path.isAbsolute(); // print isAbsolute System.out.println("Path is Absolute: " + isAbsolute); } } |
Program 2:
// Java program to demonstrate // java.nio.file.Path.isAbsolute() method import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; public class GFG { public static void main(String[] args) throws IOException { // create object of Path Path path = Paths.get("temp\\Spring"); // call isAbsolute() to get check // path is absolute or not boolean isAbsolute = path.isAbsolute(); // print isAbsolute System.out.println("Path is Absolute: " + isAbsolute); } } |
References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Path.html#isAbsolute()
Recommended Posts:
- File isAbsolute() method in Java with Examples
- Path getFileName() method in Java with Examples
- Path toAbsolutePath() method in Java with Examples
- Path getName(int) method in Java with Examples
- Path getFileSystem() method in Java with Examples
- Path toUri() method in Java with Examples
- Path toFile() method in Java with Examples
- Path resolveSibling() method in Java with Examples
- Path toString() method in Java with Examples
- Path getNameCount() method in Java with Examples
- Path compareTo() method in Java with Examples
- Path getParent() method in Java with Examples
- Path equals() method in Java with Examples
- Path hashCode() method in Java with Examples
- Path resolve() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.





