Get FileStore information in Java

Description

The following code shows how to get FileStore information.

Example


import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
/*from w w  w .ja va 2s  .  co  m*/
public class Main {
  static final long kiloByte = 1024;

  public static void main(String[] args) throws Exception {
    FileSystem fileSystem = FileSystems.getDefault();

    for (FileStore fileStore : fileSystem.getFileStores()) {
      long totalSpace = fileStore.getTotalSpace() / kiloByte;
      long usedSpace = (fileStore.getTotalSpace() - fileStore
          .getUnallocatedSpace()) / kiloByte;
      long usableSpace = fileStore.getUsableSpace() / kiloByte;
      String name = fileStore.name();
      String type = fileStore.type();
      boolean readOnly = fileStore.isReadOnly();
    }
  }
}




















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip