开发者

Create new file using JNDI

开发者 https://www.devze.com 2023-03-04 14:02 出处:网络
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.Operatio

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号