How to find the total space in a drive in Java

In this blog post, I will be explaining how you can find the total space available in a drive via Java. Consider the following code snippet:

 

package learnjava.io;import java.io.File;public class FindTotalSpaceDemo {public static void main(String[] args) {String fileName = "C:/";File file = new File(fileName);long totalSpace = file.getTotalSpace();System.out.println("totalSpace = "+totalSpace/1000000000+ " GB");}}

 

There is a method called File.getTotalspace. This returns the number of bytes available on the partition that is encapsulated by the file object.

Comments

Popular posts from this blog

How to use logging in SpringBoot with code samples

Python While Loop with code samples

How to convert a List to a Set