我想在 Java 中以编程方式编辑 Eclipse InstanceScope 首选项的一些值。
我用这个:
Preferences instancePrefsNode = InstanceScope.INSTANCE.getNode("my.pref.node");
instancePrefsNode.put("property1", "1");
instancePrefsNode.put("prefix/property2", "2");
刷新后,我进入文件 .metadata\org.eclipse.core.runtime.settings\my.pref.node.prefs :
eclipse.preferences.version=1
property1=1
//prefix/property2=2
如您所见,包含斜杠的键已以 2 个前导斜杠为前缀。
我无法去掉属性名称中的斜杠,因为属性节点是由商业 Eclipse 插件的编辑器定义的......
有人知道如何抑制这两个前导斜杠吗?
谢谢
最佳答案
使用两个首选项节点有效:
Preferences instancePrefsNode
= InstanceScope.INSTANCE.getNode("my.pref.node");
instancePrefsNode.put("property1", "1");
Preferences instancePrefsNode2
= InstanceScope.INSTANCE.getNode("my.pref.node/prefix");
instancePrefsNode2.put("property2", "2");
“//”用于区分节点中的/和首选项键中的/,因此您尝试匹配的代码必须使用两个节点,如下所示。
关于java - Eclipse 首选项(org.eclipse.core.runtime.preferences.InstanceScope): unwanted leading slashes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25847609/