Rename.java Source code

Java tutorial

Introduction

Here is the source code for Rename.java

Source

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;

public class Rename {
    public static void main(String[] args) throws Exception {
        String initialContextString = "/";

        if (args.length < 2) {
            System.out.println("Useage: java Rename filename1 filename2");
            System.exit(-1);
        }

        Hashtable env = new Hashtable();

        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
        env.put(Context.PROVIDER_URL, "file:" + initialContextString);

        Context initCtx = new InitialContext(env);
        System.out.println("Renaming " + args[0] + " to " + args[1]);
        initCtx.rename(args[0], args[1]);

    }
}