Skip to content

Instantly share code, notes, and snippets.

@TuxCoding
Created January 26, 2017 09:05
Show Gist options
  • Select an option

  • Save TuxCoding/3a9dfde88c0dd0af3ee6f3305cb9d055 to your computer and use it in GitHub Desktop.

Select an option

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
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