- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get the total space of this partition in Java
The method java.io.File.getTotalSpace() is used to obtain the total space in the form of bytes for the partition specified by the required abstract path name. This method requires no parameters and it returns the bytes for the partition i.e. its total space.
A program that demonstrates this is given as follows −
Example
import java.io.File; public class Demo { public static void main(String[] args) { File[] roots = File.listRoots(); try { for(File r : roots) { System.out.println(r); System.out.println("Total space = " + r.getTotalSpace()); } } catch(Exception e) { e.printStackTrace(); } } }
The output of the above program is as follows −
Output
C:\ Total space = 391309684736 D:\ Total space = 83885027328 E:\ Total space = 23791136768 F:\ Total space = 0
Note − The output may vary on Online Compilers.
Now let us understand the above program.
The method java.io.File.getTotalSpace() is used to obtain the total space in the form of bytes for the partition. A code snippet that demonstrates this is given as follows −
File[] roots = File.listRoots(); try { for(File r : roots) { System.out.println(r); System.out.println("Total space = " + r.getTotalSpace()); } } catch(Exception e) { e.printStackTrace(); }
- Related Articles
- Get the free space of this partition in Java
- Get the usable space of this partition in Java
- Get the ID of this timezone in Java
- Get the total number of leaves of a JTree in Java?
- How to check total space and available space in Linux using the terminal?
- Java Program to convert this duration to the total length in nanoseconds
- Java Program to convert this duration to the total length in milliseconds
- Java Program to get the number of hours in this duration
- Java Program to get the number of minutes in this duration
- Get total in the last row of MySQL result?
- Get the total number of same objects in JavaScript
- Get all characters before space in MySQL?
- Space format specifiers in Java
- How to get this nodes’s parent in a JTree with Java?
- Get the total bytes consumed by the elements in Numpy

Advertisements