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:
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
{
Path path
= Paths.get("D:\\eclipse\\configuration"
+ "\\org.eclipse.update");
boolean isAbsolute = path.isAbsolute();
System.out.println("Path is Absolute: "
+ isAbsolute);
}
}
|
Output:
Program 2:
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
{
Path path = Paths.get("temp\\Spring");
boolean isAbsolute = path.isAbsolute();
System.out.println("Path is Absolute: "
+ isAbsolute);
}
}
|
Output:
References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Path.html#isAbsolute()
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
16 Jul, 2019
Like Article
Save Article