FileUtils.copyUrlToFile 支持哪些协议?

What protocols does FileUtils.copyUrlToFile support?

commons-io FileUtils.copyUrlToFile 允许从哪些协议复制?

简答:这取决于JVM,但至少httphttpsfilejar 会起作用。

长答案:FileUils 使用 Java 的 java.net.URL 来处理实际连接。 java.net.url 使用 URLStreamHandler to implement different protocol. The handlers are found dynamically, and you can add your own. According to the Javadoc 的协议特定实例,您保证拥有 http、https、文件和 jar 处理程序:

Protocol handlers for the following protocols are guaranteed to exist on the search path :-

http, https, file, and jar

不保证每个 JVM 上都存在其他协议的处理程序。在我使用 Java 8u111 的 Windows x64 机器上,在 sun.net.www.protocol 下我还看到了 mailtoftpnetdoc 处理程序,这意味着支持这些协议。请注意,支持协议的事实并不意味着 copyUrlToFile 对它有意义(例如 mailto)