create.java
来自「J2EE 1.4程序设计教程图书配套的源代码」· Java 代码 · 共 36 行
JAVA
36 行
import javax.naming.*;
import java.io.File;
import java.util.Hashtable;
/**
* Demonstrates how to create a new subcontext called "new".
* (Run Destroy after this to remove the subcontext).
*
* usage: java Create
*/
class Create {
public static void main(String[] args) {
// Set up the environment for creating the initial context
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:/tmp/tutorial");
try {
// Create the initial context
Context ctx = new InitialContext(env);
// Create the context
Context result = ctx.createSubcontext("new");
// Check that it was created by listing its parent
NamingEnumeration list = ctx.list("");
// Go through each item in list
while (list.hasMore()) {
NameClassPair nc = (NameClassPair)list.next();
System.out.println(nc);
}
// Close the context when we're done
ctx.close();
} catch (NamingException e) {
System.out.println("Create failed: " + e);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?