J2EE 1.4程序设计教程图书配套的源代码

源代码在线查看: lookup.java

软件大小: 57 K
上传用户: jzp_home_2009
关键词: J2EE 1.4 程序设计 教程
下载地址: 免注册下载 普通下载 VIP

相关代码

				import javax.naming.*;
				import java.io.File;
				import java.util.Hashtable;
				/**
				  * Demonstrates how to look up an object.
				  *
				  * usage: java Lookup
				  */
				class Lookup {
				    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);
					    // Perform lookup and cast to target type
					    File f = (File) ctx.lookup("abc.txt");
					    System.out.println(f);
					    // Close the context when we're done
					    ctx.close();
					} catch (NamingException e) {
					    System.out.println("Lookup failed: " + e);
					}
				    }
				}
							

相关资源