我还在学习编程,目前我通过以下代码在config.properties中加载了一个java项目。
public static void run(File dir) throws IOException, URISyntaxException, Exception {
File configFile = new File(dir + File.separator + fileName);
if (!configFile.exists()) {
System.out.println("[JenkinsBot] Config file created, please edit it!");
FileGenerator.ExportResource(dir, fileName);
Main.death = true;
} else {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class).configure(params.properties().setFileName("resources/config.properties"));
Configuration cfg = builder.getConfiguration();
if (cfg != null) {
System.out.println("[JenkinsBot] Config file loaded!");
Main.discordToken = cfg.getProperty("Token").toString().replaceAll("^\"|\"$", "").replaceAll("^\'|\'$", "");
} else {
System.out.println("ERROR: " + fileName + " is null, at this point it should not be. Please check your files.");
}
}
}
由此我可以获得一个名为&#34; Token&#34;的字符串,在配置文件中看起来像这样。
# Discord token - This is required for your bot to connect. Please follow the following instructions to setup a bot.
# https://github.com/jon-skocik/Jenkins-Bot/wiki/Creating-a-discord-bot-&-getting-a-token
Token: exampletokengoeshere
我试图拉出我认为的字符串&#34;字符串列表&#34;,但我无法解决这个问题。
feeds:
- www.google.com
- www.youtube.com
- www.reddit.com
我的最终目标是让用户添加到该列表中,并让我能够遍历它们并将它们放入哈希映射中。任何帮助或方向都会很棒。我正在玩cfg.getProperties("feeds").keySet()
,但那并不是我想做的事。