Created
January 26, 2017 09:05
-
-
Save TuxCoding/3a9dfde88c0dd0af3ee6f3305cb9d055 to your computer and use it in GitHub Desktop.
Get the amount of free or total bytes on file system using the Java 7 NIO API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| long freeSpace = 0; | |
| long totalSpace = 0; | |
| try { | |
| FileStore fileStore = Files.getFileStore(Paths.get(".")); | |
| freeSpace = fileStore.getUsableSpace(); | |
| totalSpace = fileStore.getUsableSpace(); | |
| } catch (IOException ioEx) { | |
| Logger.getGlobal().log(Level.WARNING, "Cannot calculate free/total disk space", ioEx); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment