Difference between url and uri bael 864 hariprasad (#1987)
* Commit URUURLJNDIFS added.
* URI URL REST commit.
* Revert "URI URL REST commit."
This reverts commit d9e26399be.
* Difference URI URL REST BAEL-864.
* Commit Difference URI URL REST #864, small changes.
* Difference URI URL REST project has been moved to spring-rest.
* BAEL-864. Deleted unused project and did one small change.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.baeldung.filesystem.jndi;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
public class LookupFSJNDI {
|
||||
InitialContext ctx = null;
|
||||
|
||||
public LookupFSJNDI() throws NamingException {
|
||||
super();
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() throws NamingException {
|
||||
Hashtable<String, String> env = new Hashtable<String, String>();
|
||||
|
||||
env.put (Context.INITIAL_CONTEXT_FACTORY,
|
||||
"com.sun.jndi.fscontext.RefFSContextFactory");
|
||||
// URI to namespace (actual directory)
|
||||
env.put(Context.PROVIDER_URL, "file:./src/test/resources");
|
||||
|
||||
ctx = new InitialContext(env);
|
||||
}
|
||||
|
||||
public InitialContext getCtx() {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
public File getFile(String fileName) {
|
||||
File file;
|
||||
try {
|
||||
file = (File)getCtx().lookup(fileName);
|
||||
} catch (NamingException e) {
|
||||
file = null;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user