Пример #1
0
  /** File store properties examined */
  @Test
  public void testRetrieveFileStoreInforamtion() throws IOException {
    FileSystem fs = FileSystems.getDefault();
    assertNotNull(fs);

    List<FileStore> stores = iterableToList(fs.getFileStores());

    // file store is device such a drive, partition or volume
    // in my system I have 3 partitions
    assertEquals(3, stores.size());

    // for storing triples of basic file store identification
    Set<String> storeNames = new HashSet<>();
    for (FileStore store : stores) {
      storeNames.add(store.name() + ";" + store.type() + ";" + store.isReadOnly());
      long total = store.getTotalSpace();
      long unallocated = store.getUnallocatedSpace();
      long usable = store.getUsableSpace();
      assertTrue(total > 0);
      assertTrue(unallocated > 0 && total >= unallocated);
      assertTrue(usable > 0 && total >= usable);
      // Just for notice of NumberFormat class existence :)
      // System.out.println(NumberFormat.getInstance().format(total));
    }

    // environment dependent
    assertEquals(
        cSET("Windows7_OS;NTFS;false", "Data;NTFS;false", "Documents;NTFS;false"), storeNames);

    // can be used for determine if file store supports such attribute view
    assertTrue(stores.get(0).supportsFileAttributeView(BasicFileAttributeView.class));
    assertFalse(stores.get(0).supportsFileAttributeView(PosixFileAttributeView.class));
  }
Пример #2
0
 public static void main(String[] args) throws IOException {
   System.out.format("%-20s %12s %12s %12s\n", "Filesystem", "kbytes", "used", "avail");
   if (args.length == 0) {
     FileSystem fs = FileSystems.getDefault();
     for (FileStore store : fs.getFileStores()) {
       printFileStore(store);
     }
   } else {
     for (String file : args) {
       FileStore store = Files.getFileStore(Paths.get(file));
       printFileStore(store);
     }
   }
 }