How about File.isAbsolute():

File file = new File(path);
if (file.isAbsolute()) {
    ...
}
Answer from Jon Skeet on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › path-isabsolute-method-in-java-with-examples
Path isAbsolute() method in Java with Examples - GeeksforGeeks
July 16, 2019 - 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; ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › nio › file › Path.html
Path (Java Platform SE 8 )
April 21, 2026 - Implementations of this interface ... created this object. Returns: the file system that created this object · boolean isAbsolute() Tells whether or not this path is absolute....
🌐
GeeksforGeeks
geeksforgeeks.org › java › file-isabsolute-method-in-java-with-examples
File isAbsolute() method in Java with Examples - GeeksforGeeks
July 11, 2025 - 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 ... // Java program to demonstrate the // use of isAbsolute() function import java.io.*; public class solution { public static void main(String args[]) { // try-catch block to handle exceptions try { // Create a file object File f = new File("program.txt"); // Check if the given path // is absolute or not if (f.isAbsolute()) { // Display that the path is absolute // as the function returned true System.out.println("The path is absolute"); } else { // Display that the path is not absolute // as the function returned false System.out.println("The path is not absolute"); } } catch (Exception e) { System.err.println(e.getMessage()); } } }
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › java › io › file_isabsolute.htm
Java - File isAbsolute() method
The Java File isAbsolute() method checks whether this abstract pathname is absolute. Following is the declaration for java.io.File.isAbsolute() method − NA The method returns true if this abstract pathname is absolute, else the method returns ...
🌐
Stack Overflow
stackoverflow.com › questions › 76366230 › how-java-isabsolute-depends-on-path-separator-and-or-os
How Java isAbsolute() depends on path separator and/or OS? - Stack Overflow
Depends on how you define "portable": on Windows an absolute path has either the form C:\path\to\something or \\server\share\path\to\something (or as Java strings: "C:\\path\\to\\something" and "\\\\server\\share\\path\\to\\something") and for these paths Path.isAbsolute() returns true.
🌐
GeeksforGeeks
geeksforgeeks.org › java › file-getabsolutepath-method-in-java-with-examples
File getAbsolutePath() method in Java with Examples - GeeksforGeeks
July 11, 2025 - Return value: This function returns a String value which is the absolute Path of the given File object. Exception: This method throws Security Exception if the required property value cannot be accessed.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › nio › file › Path.html
Path (Java Platform SE 7 )
Implementations of this interface ... created this object. Returns: the file system that created this object · boolean isAbsolute() Tells whether or not this path is absolute....
🌐
Initial Commit
initialcommit.com › blog › java-io-difference-absoluterelative-canonical-path
Java IO: difference between absolute,relative and canonical path
July 28, 2017 - Finally, getPath() always returns the argument of the constructor as it is, regardless if it’s absolute or relative. getAbsolutePath() and getCanonicalPath() both return an absolute path of the file, however it’s recommended to always use the canonical path since it doesn’t contain the special characters “.” and “..”, hence makes it feasible to be used in comparison operations. The common way of accessing the file system in java is through the java.io.File API.
🌐
Stack Overflow
stackoverflow.com › questions › 68348448 › how-does-the-isabsolute-method-runjava
path - How does the isAbsolute method run[Java]? - Stack Overflow
Path path= Paths.get("D:\\Example\\1.txt"); System.out.println(path.isAbsolute());//prints true ... Because Paths.get returns an object that implements the Path-interface. ... Are you interested in the implementation of the mechanism, or the concepts? For the implementation, see: stackoverflow.com/questions/1543191/method-overriding-in-java
🌐
Oracle
docs.oracle.com › en › java › javase › 13 › docs › api › java.base › java › nio › file › Path.html
Path (Java SE 13 & JDK 13 )
boolean isAbsolute() Tells whether or not this path is absolute. An absolute path is complete in that it doesn't need to be combined with other path information in order to locate a file. Returns: true if, and only if, this path is absolute · Path getRoot() Returns the root component of this ...
🌐
Medium
medium.com › @AlexanderObregon › javas-paths-get-method-explained-9586c13f2c5c
Java’s Paths.get() Method Explained | Medium
September 8, 2024 - Understanding the difference between relative and absolute paths is crucial when working with Paths.get(). Paths in Java can either be absolute, meaning they specify the location of a file or directory from the root of the file system, or relative, ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-getcanonicalpath-and-getabsolutepath-in-java
Difference Between getCanonicalPath() and getAbsolutePath() in Java - GeeksforGeeks
June 3, 2022 - But if the file path mentioned during file object creation is like "C:/folder1/folder2/folder3/folder4/../../folder3/file.txt", then the absolute file path will be the same as the mentioned path, but the canonical file path will be the shortest absolute path, i.e. "C:/folder1/folder2/folder3/file.txt". ... // Java Program to illustrate Difference Between // getCanonicalPath() and getAbsolutePath() // Importing input output classes import java.io.*; // Main class class GFG { // Main driver method public static void main(String[] args) throws IOException { // Path of Test.txt is E:\workspace\gfg