Java FileSystem create platform-specific default file system object

Description

Java FileSystem create platform-specific default file system object

import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;

public class Main {
  public static void main(String[] args) throws Exception{
    FileSystem fs = FileSystems.getDefault();
    System.out.println("Read-only file system: " + fs.isReadOnly());
    System.out.println("File name separator: " + fs.getSeparator());

    System.out.println("\nAvailable file-stores are");

    for (FileStore store : fs.getFileStores()) {
      String desc = store.toString();
      String type = store.type();
      System.out.println("type:"+type);
      long totalSpace = store.getTotalSpace();
      long unallocatedSpace = store.getUnallocatedSpace();
      long availableSpace = store.getUsableSpace();
      System.out.println(desc + ", Total: " + totalSpace + ", Unallocated: "
          + unallocatedSpace + ", Available: " + availableSpace);
    }/*  w w w  .  ja v  a  2s .  com*/
  }
}



PreviousNext

Related