有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何加载http。txt文件作为Java文件系统

我正在学习Java 1.8 OCP考试,我在Oracle学习指南p.459中遇到了一些内容,其中说可以将远程URL作为文件系统对象加载。我试过了,但没法用。最简单的hello world风格的答案是什么

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());
    }
}

它抛出了一个错误:

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)

增编: FileSystemProvider。installedProviders()返回

[sun.nio.fs。MacOSXFileSystemProvider@4554617c,com。太阳尼奥。齐普夫。ZipFileSystemProvider@74a14482]


共 (0) 个答案