File getUsableSpace() in Java

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

Syntax:

long java.io.File.getUsableSpace()

This method returns the number of bytes available to this virtual machine on the partition named by this abstract pathname.

Note: If the number of available bytes in the partition is greater than Long.MAX_VALUE, then Long.MAX_VALUE will be returned.

Parameters: NA

Returns: The number of available bytes on the partition or 0Lif the abstract pathname does not name a partition or if this number cannot be obtained.

Throws:

SecurityException - If a security manager has been installed and it denies RuntimePermission("getFileSystemAttributes") or its SecurityManager.checkRead(String) method denies read access to the file named by this abstract pathname.

Approach

Java

import java.io.File;

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

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

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

    }
}

Output:

144047235072


No comments:

Post a Comment