1) { String key = keyValuePair[0]; String value = keyValuePair[1]; if (DupKeyOption.OVERWRITE == dupKeyOption) { map.put(key, value); } else if (DupKeyOption.DISCARD == dupKeyOption) { map.putIfAbsent(key, value); } } else { System.out.println("No Key:Value found in line, ignoring: " + line); } } } catch (IOException e) { e.printStackTrace(); } return map; }"> 1) { String key = keyValuePair[0]; String value = keyValuePair[1]; if (DupKeyOption.OVERWRITE == dupKeyOption) { map.put(key, value); } else if (DupKeyOption.DISCARD == dupKeyOption) { map.putIfAbsent(key, value); } } else { System.out.println("No Key:Value found in line, ignoring: " + line); } } } catch (IOException e) { e.printStackTrace(); } return map; }"> 1) { String key = keyValuePair[0]; String value = keyValuePair[1]; if (DupKeyOption.OVERWRITE == dupKeyOption) { map.put(key, value); } else if (DupKeyOption.DISCARD == dupKeyOption) { map.putIfAbsent(key, value); } } else { System.out.println("No Key:Value found in line, ignoring: " + line); } } } catch (IOException e) { e.printStackTrace(); } return map; }">

Untitled

Untitled

public static Map<String, String> byBufferedReader(String filePath, DupKeyOption dupKeyOption) {
    HashMap<String, String> map = new HashMap<>();
    String line;
    try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
        while ((line = reader.readLine()) != null) {
            String[] keyValuePair = line.split(":", 2);
            if (keyValuePair.length > 1) {
                String key = keyValuePair[0];
                String value = keyValuePair[1];
                if (DupKeyOption.OVERWRITE == dupKeyOption) {
                    map.put(key, value);
                } else if (DupKeyOption.DISCARD == dupKeyOption) {
                    map.putIfAbsent(key, value);
                }
            } else {
                System.out.println("No Key:Value found in line, ignoring: " + line);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return map;
}