package exercise04; import java.io.*; import java.util.HashMap; import java.util.Map; public class PropertyReader { public static void main(String[] args) throws IOException { try { BufferedReader reader = new BufferedReader(new FileReader(args[0])); Map props = readProps(reader); for (String key : props.keySet()) { System.out.println(key + ": " + props.get(key)); } } catch (WrongPropertySyntaxException e) { System.err.println(e.getMessage()); } catch (FileNotFoundException e) { System.err.println("File not found."); } } private static Map readProps(BufferedReader reader) throws IOException { String line; Map res = new HashMap<>(); try { while ((line = reader.readLine()) != null) { String[] split = line.split(":"); if (split.length == 2) { res.put(split[0].trim(), split[1].trim()); } else { throw new WrongPropertySyntaxException("Property file is not good"); } } } finally { reader.close(); } return res; } }