How to get full disk space on Linux with Java?

I can get free disk space. How to get the total disk space?

My code is:

import java.io.IOException; import org.apache.commons.io.FileSystemUtils; public class DiskSpace { public static void main(String[] args) { try { //calculate free disk space double freeDiskSpace = FileSystemUtils.freeSpaceKb(args[0]); System.out.println(args[0]); //convert the number into gigabyte double freeDiskSpaceGB = freeDiskSpace / 1024 / 1024; System.out.println("Free Disk Space (GB):" + freeDiskSpaceGB); } catch (IOException e) { e.printStackTrace(); } } } 

FileSystemUtils no method for shared disk space ??? hopes for your answer

Thanks in advance

+4
source share
2 answers

to try

  System.out.println(new File("/").getTotalSpace()/1024/1024/1024); //in GB 
+4
source

If you use Java6, the File class will execute:

 public long getTotalSpace() public long getFreeSpace() public long getUsableSpace() 
+6
source

Source: https://habr.com/ru/post/1398759/


All Articles