java.nio.file.FileSystems Class in Java Last Updated : 21 Apr, 2021 Comments Improve Suggest changes Like Article Like Report java.nio.file.FileSystems class acts as a factory for creating new file systems. This class provides methods for creating file systems. This file system act as factories for creating different objects like Path, PathMatcher, UserPrincipalLookupService, and WatchService. This object helps to access the files and other objects in the file system. Syntax: Class declaration public final class FileSystems extends Object Methods of this class is as follows: MethodDescriptiongetDefault()This method returns a new default FileSystem.getFileSystem(URI uri)This method returns a reference to an existing FileSystem.newFileSystem(Path path, ClassLoader loader)This method is used to construct a new FileSystem to access the contents of the files of this file system.newFileSystem(URI uri, Map<String,?> env)This method is used to create a new File system using the given URInewFileSystem(URI uri, Map<String,?> env, ClassLoader loader)This method is used to create a new File system using the given URI Example 1: Java // Java Program to illustrate FileSystems Class by // creating a new file system using getDefault() method and // printing its file stores and root directories // Importing classes from java.nio package // for network linking import java.nio.file.FileStore; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Path; // Main class public class GFG { // Main driver method public static void main(String[] args) { // Try block to check for exceptions try { // Create a new file system by // creating object of FileSystem class // using getDefault() method FileSystem filesystem = FileSystems.getDefault(); // Display commands only System.out.println( "File System created successfully"); System.out.println( "Underlying file stores of this FileSystem :"); // Printing the underlying file stores of this // FileSystem using for each loop for (FileStore store : filesystem.getFileStores()) { // Print statement System.out.println(store.toString()); } // Display message only System.out.println( "Root directories of this FileSystem :"); // Printing the root directories of this // FileSystem using for each loop for (Path rootdir : filesystem.getRootDirectories()) { // Print statement System.out.println(rootdir.toString()); } } // Catch block to handle the exceptions catch (Exception e) { // Print the exception along with line number // using printStackTrace() method e.printStackTrace(); } } } Output: Example 2: Java // Java Program to illustrate FileSystems Class by // creating new file system using newFileSystem() method // Importing URI class from java.net package import java.net.URI; // Importing required file classes from java.nio package import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.Paths; // Importing Map and HashMap classes from java.util package import java.util.HashMap; import java.util.Map; // Main class public class GFG { // Main driver method public static void main(String[] args) { // Try block to check for exceptions try { // Creating object of Map class // Declaring object of string types Map<String, String> env = new HashMap<>(); // Getting path of zip file Path zipPath = Paths.get("ZipFile.zip"); // Creating URI from zip path received URI Uri = new URI("jar:file", zipPath.toUri().getPath(), null); // Create new file system from uri FileSystem filesystem = FileSystems.newFileSystem(Uri, env); // Display message for better readability System.out.println( "FileSystem created successfully"); // Checking if file system is open or not // using isOpen() method if (filesystem.isOpen()) // Print statement System.out.println("File system is open"); else // Print statement System.out.println("File system is close"); } // Catch block to handle the exceptions catch (Exception e) { // Print the exception with line number // using the printStack() method e.printStackTrace(); } } } Output: File System created successfully File system is open Comment More infoAdvertise with us Next Article java.nio.file.FileSystems Class in Java A abhinavjain194 Follow Improve Article Tags : Java Java-NIO package Practice Tags : Java Similar Reads java.nio.file.FileSystem class in java java.nio.file.FileSystem class provides an interface to a file system. The file system acts as a factory for creating different objects like Path, PathMatcher, UserPrincipalLookupService, and WatchService. This object help to access the files and other objects in the file system. Syntax: Class decla 4 min read java.nio.file.FileStore Class in Java Java.nio.file is a package in java that consists of the FileStore class. FileStore class is a class that provides methods for the purpose of performing some operations on file store. FileStore is a class that extends Object from java.lang package. And few methods the FileStore class can inherit from 4 min read java.nio.file.spi.FileTypeDetector Class in Java java.nio.file.spi.FileTypeDetector Class extends java.lang.Object Class. FileTypeDetector Class contain method to know about the content type of given file. Class declaration: public abstract class FileTypeDetector extends ObjectConstructor: ConstructorDescriptionprotected FileTypeDetector()It is us 2 min read java.nio.file.attribute.FileTime Class in Java The java.nio.file.attribute.FileTime class is used to get a value representing this file's timestamp i.e, the time when this file was last modified, accessed, or created. Class Declaration: public final class FileTime extends Object implements Comparable<FileTime>Methods: MethodDescriptioncomp 2 min read java.nio.file.Paths Class in Java java.nio.file.Paths class contains static methods for converting path string or URI into Path. Class declaration : public final class Paths extends ObjectMethods: MethodDescriptionget(String first, String... more) This method converts a path string, or a sequence of strings that when joined form a p 2 min read Like