package com.javarush.task.task20.task2003;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

/*
Знакомство с properties
*/
public class Solution {
    public static Map<String, String> properties = new HashMap<>();

    public void fillInPropertiesMap() throws Exception {
        //implement this method - реализуйте этот метод
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String fileName = br.readLine();
        br.close();

        FileInputStream fis = new FileInputStream(fileName);
        load(fis);
        fis.close();
    }

    public void save(OutputStream outputStream) throws Exception {
        //implement this method - реализуйте этот метод
        PrintWriter printWriter = new PrintWriter(outputStream);
        for (Map.Entry<String, String> item: properties.entrySet())
            printWriter.println(item.getKey() + " : " + item.getValue());
        printWriter.flush();
        printWriter.close();
    }

    public void load(InputStream inputStream) throws Exception {
        //implement this method - реализуйте этот метод
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String line;
        properties.clear();
        while ((line = reader.readLine()) != null) {
            String[] strArr = line.split(" : ");
            properties.put(strArr[0], strArr[1]);
        }
        reader.close();
    }

    public static void main(String[] args) throws Exception {

    }
}