0

I am studying for the Java 1.8 OCP exam and I ran across something in the Oracle study guide p.459 where it says you can load a remote URL as a FileSystem object. I tried this and can't get it to work. What is the simplest hello-world style answer to get this working?

import java.net.*;
import java.nio.file.*;
public class FileTest {
    public static void main(String[] args) throws URISyntaxException, MalformedURLException {
        FileSystem remoteFS = FileSystems.getFileSystem(
            new URI("http://www.gutenberg.org/files/55007")
        );
        Path remotePath = remoteFS.getPath("55007-0.txt");
        System.out.println(remotePath.isAbsolute());
    }
}

It throws the error:

Exception in thread "main" java.nio.file.ProviderNotFoundException: 
  Provider "http" not found
    at java.nio.file.FileSystems.getFileSystem(FileSystems.java:224)
    at qa.test.FileTest.main(FileTest.java:7)

Addendum: FileSystemProvider.installedProviders() returns

[sun.nio.fs.MacOSXFileSystemProvider@4554617c, com.sun.nio.zipfs.ZipFileSystemProvider@74a14482]

djangofan
  • 28,471
  • 61
  • 196
  • 289
  • " where it says you can load a remote URL as a FileSystem object." Are you sure ? The method takes as parameter an URI and not an URL. It doesn't make no sense to provide an URL as an URL is not necessary compatible with all FileSystems. – davidxxx Jul 02 '17 at 18:04
  • @davidxx Yes, the JavaDoc says it takes a URI. I followed a whole rabbit trail down Google searches and couldn't figure it out. Seems like 'http provider' would/should be built-in but it appears I need to do something special, like write a custom handler that converts the URI to a URL (among other things)? – djangofan Jul 02 '17 at 18:15
  • 1
    `FileSystemProvider.installedProviders()` returns a list of installed providers. – gommb Jul 02 '17 at 18:41
  • What is the exact wording? – user207421 Jul 03 '17 at 01:39
  • what if you use `file://` or `ftp://` over http? –  Jul 07 '17 at 19:23

0 Answers0