File getAbsolutePath() in Java

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

Syntax:

String java.io.File.getAbsolutePath()

This method returns the absolute pathname string of this abstract pathname.

Parameters: NA

Returns: The absolute pathname string denoting the same file or directory as this abstract pathname.

Throws:

SecurityException - If a required system property value cannot be accessed.

Approach

Java

import java.io.File;

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

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

        System.out.println(file.getAbsolutePath());
    }
}

Output:

D:\hello.txt


No comments:

Post a Comment