Sunday, 16 June 2019

NIO2: Get default file system

'FileSystems.getDefault()' method return default FileSystem.

App.java
package com.sample.app;

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

public class App {

 public static void main(String args[]) {

  FileSystem fileSystem = FileSystems.getDefault();

  Iterable<Path> paths = fileSystem.getRootDirectories();

  for (Path path : paths) {
   System.out.println(path);
  }
 }
}


If you are using windows file system with root directories C:, D:, E:, F: then this getRootDirectories method return all these 4 directories.

Previous                                                 Next                                                 Home

No comments:

Post a Comment