-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathDiskInfoEx.java
More file actions
31 lines (23 loc) · 1003 Bytes
/
DiskInfoEx.java
File metadata and controls
31 lines (23 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.zetcode;
import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
public class DiskInfoEx {
public static void main(String[] args) {
FileSystem fileSystem = FileSystems.getDefault();
System.out.printf("%30s | %10s | %23s | %20s \n", "", "Type", "Total space", "Free space");
System.out.println("-------------------------------------------------"
+ "----------------------------------------------------------");
Iterable<FileStore> it = fileSystem.getFileStores();
it.forEach(fileStore -> {
try {
System.out.printf("%30s | %10s | %20s GB | %20s GB\n", fileStore, fileStore.type(),
(fileStore.getTotalSpace() / 1073741824f),
(fileStore.getUsableSpace() / 1073741824f));
} catch (IOException e) {
e.printStackTrace();
}
});
}
}