Create new file using JNDI
I am trying to use JNDI to create a new binding while using 'RefFSContextFactory'. So what i am trying to do create a new File using JNDI. However this code throws an exception javax.naming.OperationNotSupportedException: Can only bind References or Referenceable objects.
import javax.naming.Context;
import javax.naming.InitialContext;
import java.io.IOException;
import java.util.Hashtable;
public class Main2 {
public static void main(String [] rgstring) throws IOException {
try {
Hashtable<String,String> hashtableEnvironment = new Hashtable<String,String>();
hashtableEnvironment.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory"
);
hashtableEnvironment.put(
Context.PROVIDER_URL,
"file:///TestingApps/"
);
Context context = new InitialContext(hashtableEnvironment);
//File f=new File("C:\\TestingApps\\test");
//f.createNewFile();
context.bind("test", null);
context.close();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
}
Is this possible using JNDI? Should the bound object be an object of File and canno开发者_Go百科t be null?
So what i am trying to do create a new File using JNDI.
(a) Why? f.createNewFile() does that.
(b) You can't.
(c) That's not what JNDI is for, or the file-system provider either. It is for recording bindings in a file, or files.
As you were also told on the Oracle forums.
精彩评论