Drive space usage information in JAVA

This JAVA code gives the dpace usage by the ‘c:’ drive you can modify it for others.

Code:

package com.oksbwn.systeminteraction;
import java.io.File;
public class DiskSpaceDetail
{
public String FreeSpaceInDrive()
{
String space="";
File file = new File("C:");
long totalSpace = file.getTotalSpace(); //total disk space in bytes.
long usableSpace = file.getUsableSpace(); ///unallocated / free disk space in bytes.
space=space+"C:";
space="T: "+ totalSpace /1024 /1024 + " MB F: "+ usableSpace /1024 /1024+" MB";
return space;
}
}
Catch Me On

Bikash Panda

Blogger / Embedded System Developer at WGLabz
A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.
Bikash Panda
Catch Me On

Latest posts by Bikash Panda (see all)

Related posts