Sunday 16 June 2019

NIO2: Introducing FileSystemProvider class

FileSystemProvider is a Service-provider class for file systems.

This is an abstract class. All the concrete file system provider implementations must implement the abstract methods of this class.

A provider is identified by the scheme. Below snippet return all the filesystem providers that are installed in your system.

App.java
package com.sample.app;

import java.io.IOException;
import java.nio.file.spi.FileSystemProvider;
import java.util.List;

public class App {

    public static void main(String args[]) throws IOException {

        List<FileSystemProvider> fileSystemProviders = FileSystemProvider.installedProviders();

        for (FileSystemProvider fileSystemProvider : fileSystemProviders) {
            System.out.println(fileSystemProvider.getScheme());
        }

    }
}


Output

file
jar



Previous                                                 Next                                                 Home

No comments:

Post a Comment