Config File Parser in Java: Explanation & Practice
Parse a key=value configuration file
Problem summary
Read a config file with key=value pairs and provide get(key) functionality.
Starter code
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
// Read config.properties
// Parse key=value pairs
// Print value for given key
}
}Expected output and test cases
- Get host
database.host = localhost
- Get port
database.port = 5432
- Missing key
Key not found
Hints
- Use Properties class or custom parsing
- Split each line by =
- Store in HashMap
Related File I/O exercises
- Practice Word Frequency Counter in Java
- Practice Simple File Encryption in Java
- Practice File Difference Checker in Java
Practice all File I/O exercises · Run this idea in the Java compiler