⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rename.java

📁 J2EE 1.4程序设计教程图书配套的源代码
💻 JAVA
字号:
import javax.naming.*;
import java.io.File;
import java.util.Hashtable;
/**
  * Demonstrates how to rename an object.
  *
  * usage: java Rename
  */
class Rename {
    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);
	    // Rename to abc1.txt
	    ctx.rename("abc.txt", "abc1.txt");
	    // Check that it is there using new name
	    Object obj = ctx.lookup("abc1.txt");
	    System.out.println(obj);
	    // Rename back to abc.txt
	    ctx.rename("abc1.txt", "abc.txt");
	    // Check that it is there with original name
	    obj = ctx.lookup("abc.txt");
	    System.out.println(obj);
	    // Close the context when we're done
	    ctx.close();
	} catch (NamingException e) {
	    System.out.println("Rename failed: " + e);
	}
    }
}

⌨️ 快捷键说明

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