Plug-in cannot read or write files

When developing a text analysis plug-in, need to read and write dic directory:

package com.lietu.bigramSeg;

import org.apache.lucene.analysis.Tokenizer;
import org.elasticsearch.plugin.analysis.TokenizerFactory;
import org.apache.lucene.util.AttributeFactory;
import org.elasticsearch.plugin.NamedComponent;

@NamedComponent(value = "cn_tokenizer")
public class BigramTokenizerFactory implements TokenizerFactory {

	@Override
	public Tokenizer create() {
		AttributeFactory factory = AttributeFactory.DEFAULT_ATTRIBUTE_FACTORY;
		String dicPath = "./dic/";
		BigramDictioanryPrev dict = BigramDictioanryPrev.getInstance(dicPath);
		return new NgramTokenizer(factory, dict);
	}

}

When using this plug-in, elasticsearch output error:

[2025-02-05T14:17:53,025][WARN ][stderr                   ] [DESKTOP-GS2A859] java.security.AccessControlException: access denied ("java.io.FilePermission" ".\dic\ArrayNodeInfofile.dat" "read")

That's due to the Security Manager.

You need to include a plugin security policy, and you may need to wrap the call in a doPrivileged block

Is there a code example of read and write files?

When I try to add the following code:

AccessController.doPrivileged(
  // sensitive operation
);

IDE report error: 'java.security.AccessController' is deprecated since version 17 and marked for removal