Here’s how to load properties from a file in Java.
Given the following src/main/resources/config.properties
file:
pool-size=42 active=true
The following code will output: {pool-size=42, active=true}
import java.io.IOException; import java.util.Properties; public class LoadProperties { public static void main(String[] args) throws IOException { var properties = new Properties(); try (var stream = LoadProperties.class.getClassLoader().getResourceAsStream("config.properties")) { properties.load(stream); } System.out.println(properties); } }
If you have any questions, leave a comment or ask me on my social media.