Print.java Source code

Java tutorial

Introduction

Here is the source code for Print.java

Source

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Hashtable;

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

public class Print {
    public static void main(String[] args) throws Exception {
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");

        env.put(Context.PROVIDER_URL, "file:/tmp/marketing");

        Context initCtx = new InitialContext(env);
        File f = (File) initCtx.lookup("reports/report1.txt");
        if (f != null) {
            BufferedReader br = new BufferedReader(new FileReader(f));
            String l = null;
            while ((l = br.readLine()) != null)
                System.out.println(l);
        }

    }
}