How to read a properties file

Question from Kiryo#9472

i need to make that my app shows the specific value in xml file should i use scanner? or there is another way i need to extract

# Rate Exp Sp
RateXp = 4.
RateSp = 4.

the value of for example this^

actually not the xml but .properities

Get your .properties file as an input stream, then

final var properties = new Properties();
try (InputStream is = ...) {
    properties.load(is);
}

Easy peasy, then just

properties.getProperty("RateXp");

Full example:

public record Config(int rateXp, int rateSp) {
    public static Config loadFromClasspath() {
        final var properties = new Properties();
        try (final var inputStream = getClass().getClassLoader().getResourceAsStream("config.properties")) {
            properties.load(inputStream);
        }
        catch (IOException e) {
            throw new UncheckedIOException(e);
        }
        return new Config(
            Integer.parseInt(properties.getProperty("RateXp")),
            Integer.parseInt(properties.getProperty("RateSp"))
        );
    }
}

<- Index