I have the feeling that informations is missing to resolve 4th and 5th requirements.
Can you help me ?
thks
package fr.codegym.task.task20.task2003;
import java.io.*;
import java.util.*;
/*
Présentation de .properties
*/
public class Solution {
public static Map<String, String> properties = new HashMap<>();
public void fillInPropertiesMap() throws Exception {
// Implémente cette méthode
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
FileInputStream inStream = new FileInputStream(in.readLine());
in.close();
load(inStream);
/*
BufferedReader r = new BufferedReader(new InputStreamReader(inStream));
String line = "";
while ((line = r.readLine()) != null) {
if (line.startsWith("#") || line.startsWith("!")) continue;
String[] arrLine = line.split("=",2);
String key = arrLine[0].trim();
String value = arrLine[1].trim();
properties.put(key,value);
}
r.close();
*/
}
public void save(OutputStream outputStream) throws Exception {
// Implémente cette méthode
PrintWriter w = new PrintWriter(outputStream);
String isMap = properties.size() > 0 ? "oui" : "non";
w.println(isMap);
w.flush();
if (isMap.equals("oui")) {
for (Map.Entry<String,String> paire : properties.entrySet()) {
w.println(paire.getKey() + " = " + paire.getValue());
w.flush();
}
}
w.flush();
w.close();
}
public void load(InputStream inputStream) throws Exception {
// Implémente cette méthode
BufferedReader r = new BufferedReader(new InputStreamReader(inputStream));
String line = r.readLine();
if (line.equals("oui")) {
while ((line= r.readLine()) != null) {
String[] arrLine = line.split("=");
String key = arrLine[0].trim();
String value = arrLine[1].trim();
properties.put(key,value);
}
}
r.close();
}
public static void main(String[] args) {
}
}