79275813

Date: 2024-12-12 16:16:03
Score: 0.5
Natty:
Report link

This is how you are able to load and read external file properties:

import java.io.InputStream;
import java.util.Properties;

InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/custom.properties");
Properties customProperties = new Properties();
try {
    customProperties.load(inputStream);
} catch (IOException e) {
    e.printStackTrace();
    logger.error("IOException caught while reading properties file: " + e.getMessage());
}

if( customProperties.get("prop1") != null )
    boolean prop1 = Boolean.parseBoolean((String) customProperties.get("prop1"));
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Misone