9. Configuration Properties & File Management

Java Properties Files

Store configuration in config.properties:
base.url=https://targetqa.com
browser=chromium
headless=true
timeout=30

Read dynamically in Java:

import java.io.*;
import java.util.Properties;

public class ConfigReader {
private static Properties properties = new Properties();

public static void loadConfig(String filePath) throws IOException {
try (InputStream input = new FileInputStream(filePath)) {
properties.load(input);
}
}

public static String getProperty(String key) {
return properties.getProperty(key);
}
}

Task

  • Implement ConfigReader mock helper:
  • 1. Create a method getOrDefault(Properties props, String key, String defaultValue).
  • 2. Return props.getProperty(key) if not null, otherwise return defaultValue.
πŸ’‘Common doubts
Did you like the problem?
Lesson 9 of 44
Java
Loading code editor…
Next