File isAbsolute() in Java

isAbsolute(): This method is available in the java.io.File class of Java.

Syntax:

boolean java.io.File.isAbsolute()

This method tests whether this abstract pathname is absolute. The definition of absolute pathname is system dependent.

Note:

1. On UNIX systems, a pathname is absolute if its prefix is "/".

2. On Microsoft Windows systems, a pathname is absolute if its prefix is a drive specifier followed by "\\", or if its prefix is "\\\\".

Parameters: NA

Returns: true if this abstract pathname is absolute, false otherwise.

Exceptions: NA

Approach

Java

import java.io.File;

public class FileisAbsolute {
    public static void main(String[] args) {

        String pathname = "D:\\hello.txt";
        File file = new File(pathname);

        System.out.println(file.isAbsolute());

    }
}

Output:

true


No comments:

Post a Comment