官方介绍
public abstract class URLStreamHandler extends ObjectThe abstract class
URLStreamHandler
is the common superclass for all stream protocol handlers. A stream protocol handler knows how to make a connection for a particular protocol type, such ashttp
,ftp
, orgopher
.In most cases, an instance of a
URLStreamHandler
subclass is not created directly by an application. Rather, the first time a protocol name is encountered when constructing aURL
, the appropriate stream protocol handler is automatically loaded.
抽象类URLStreamHandler是所有流协议处理程序的通用父类。流协议处理程序知道如何为特定协议类型(如http、ftp或gopher)建立连接。
在大多数情况下,URLStreamHandler子类的实例不是由应用程序直接创建的。相反,在构造URL时第一次遇到协议名时,会自动加载相应的流协议处理程序。
扩展
在Java中,将不同来源的资源抽象成URL,通过注册不同的handler(URLStreamHandler)来处理不同来源的资源的读取逻辑。一般handler的类型使用不同前缀来识别。比如:"file :"、"http :"、"jar :"。