getTotalSpace(): This method is available in the java.io.File class of Java.
Syntax:
long java.io.File.getTotalSpace()
This method returns the size of the partition named by this abstract pathname. If the total number of bytes in the partition is greater than Long.MAX_VALUE, then Long.MAX_VALUE will be returned.
Parameters: NA
Returns: The size, in bytes, of the partition or 0L if this abstract pathname does not name a partition or if the size 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 by this abstract pathname
Approach
Java
import java.io.File;public class FilegetTotalSpace {public static void main(String[] args) {String pathname = "D:\\hello.txt";File file = new File(pathname);System.out.println(file.getTotalSpace());}}
Output:
209713098752
No comments:
Post a Comment