testfactory.java

来自「java的经典例子」· Java 代码 · 共 29 行

JAVA
29
字号
import java.net.*;import java.util.Hashtable;public class TestFactory implements URLStreamHandlerFactory {    static Hashtable handlers = new Hashtable();    public URLStreamHandler createURLStreamHandler(String protocol) {        // try cached handlers first        URLStreamHandler handler = (URLStreamHandler)handlers.get(protocol);        if (handler == null) {            String className = "Test" + protocol + "Handler";            try {                handler = (URLStreamHandler)Class.                    forName(className).newInstance();            } catch (ClassNotFoundException e) {                handler = null;                 // not found            } catch (Exception e) {                // all other exceptions, print out problem                e.printStackTrace();                handler = null;            }                        if (handler != null)                handlers.put(protocol, handler); // put into cache        }        return (handler);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?