package ru.job4j.io;

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

/**
 * Created by Intellij IDEA.
 * User: Vitaly Zubov.
 * Email: Zubov.VP@yandex.ru.
 * Version: $Id$.
 * Date: 11.08.2019.
 */
public class Config {
    private final String path;
    private final Map<String, String> values = new HashMap<>();

    /**
     * Constructor.
     *
     * @param path - path.
     */
    public Config(final String path) {
        this.path = path;
    }

    /**
     * Load file.
     */
    public void load() {
        try (
                FileReader fr = new FileReader(new File(this.path));
                BufferedReader reader = new BufferedReader(fr)) {
            String line = reader.readLine();
            while (line != null) {
                if (!line.equals("") && !line.contains("##")) {
                    String[] data = line.split("=");
                    this.values.put(data[0], data[1]);
                }
                line = reader.readLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Get value.
     *
     * @param key - key.
     * @return - value.
     */
    public String value(String key) {
        return this.values.get(key);
    }

    @Override
    public String toString() {
        StringJoiner out = new StringJoiner(System.lineSeparator());
        try (BufferedReader read = new BufferedReader(new FileReader(this.path))) {
            read.lines().forEach(out::add);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return out.toString();
    }

    public static void main(String[] args) {
        Config con = new Config("C:\\projects\\ZubovVP\\chapter_009\\src\\main\\java\\ru\\job4j\\app.properties");
        //this.getClass().getResource("/img.png")
        con.load();
//        System.out.println(con.toString());
        System.out.println(con.value("hibernate.connection.password"));
    }
}
@@ -1649,361 +1649,6 @@
    %7D
-%0A%0A    public static void main(String%5B%5D args) %7B%0A        Config con = new Config(%22C:%5C%5Cprojects%5C%5CZubovVP%5C%5Cchapter_009%5C%5Csrc%5C%5Cmain%5C%5Cjava%5C%5Cru%5C%5Cjob4j%5C%5Capp.properties%22);%0A        //this.getClass().getResource(%22/img.png%22)%0A        con.load();%0A//        System.out.println(con.toString());%0A        System.out.println(con.value(%22hibernate.connection.password%22));%0A    %7D
 %0A%7D

Correct config.