0

I have been using NIO2 file paths for accessing local file system resources. However, when I try to use the same API for non-local file systems, then I get following exception:

Exception in thread "main" java.nio.file.FileSystemNotFoundException: 
    Provider "http" not installed. Code snippet can be found below

Path toFileSystem= Paths.get(new URI("http://www.wiley.com"));

I'd like to confirm that there is a way to add http into FileSystemProvider? or is there a good guide I can follow to access non-local schemas through NIO2 API?

Neil Locketz
  • 4,228
  • 1
  • 23
  • 34

1 Answers1

3

I don't think there is a HTTP file system provider that comes with the std library. This is because there are different ways to structure the "file system" on the other end, and no sensible default.

This link explains the NIO stuff in a pretty comprehensive way: https://docs.oracle.com/javase/tutorial/essential/io/fileio.html .

You're actually constructing this Path correctly, but the problem is you don't have a FileSystemProvider that is registered with the http scheme.

Good news is you can make your own: https://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/filesystemprovider.html

Neil Locketz
  • 4,228
  • 1
  • 23
  • 34
  • Right, the JDK has 3 built-in file system providers (file, jrt, and jar). If someone has a file system provider for HTTP then it needs to be installed on the class path (or module path) so that it be loaded as a FileSystemProvider implementation. – Alan Bateman Jun 27 '18 at 09:42