Retrieve a Java object from a file on the local file system using JDNI

You can bind an object into a context, provided your object is a Reference or implements the Referenceable interface. The object is stored in a file called .bindings as a set of properties.

The following example shows how to read the object created in the QA How do I store a Java object in a file on the local file system using JNDI?.

import javax.naming.event.*;
import javax.naming.*;
import java.util.*;
public class Read
   public static void main(String []args) {
      try {
         Properties properties = new Properties();
         properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
         properties.put(Context.PROVIDER_URL, "file:///");
         InitialContext ctx = new InitialContext(properties);
         Context context = (Context) ctx.lookup("c:\temp\");
         Member member = (Member) context.lookup("member.obj");
      catch(NamingException ne) {

prints out:

[Joris Van den Bogaert,]