如何跳转到 Java 属性文件中的某个部分?

nat*_*j07 2 java properties sections

我有一个 Java 属性文件,其中有许多不同的属性用于不同的事情:

ui.datasource.st.name=MyTest
ui.datasource.st.port=111
ui.datasource.st.ip=1.1.1.1
ui.outputtype.snapshot=Snapshot
ui.outputtype.spreadsheet=Spreadsheet - xls
Run Code Online (Sandbox Code Playgroud)

该文件比这个大得多。

我想跳转到ui.outputtype部分,而不循环遍历文件并检查键值。

有没有办法做到这一点?

Zed*_*Zed 5

您应该加载属性,然后可以通过其键获取值:

Properties props = new Properties();
props.load(new FileInputStream("my.properties"));

props.getProperty("ui.outputtype.snapshot");
Run Code Online (Sandbox Code Playgroud)