Все я сдался, не знаю че не правильно, есть подозрения что Юникод не загружается, хотя не уверен как должно работать.
Создаю properties с main, загружаю с файла: file1.txt, сохраняю в файл: file2.txt, потом загружаю из сохраненного файла: file2.txt
По логике символ ∂ (\u2205), в конце должен загружатся из файла как символ а не как (\u2205)
Поправка линия 76 должна быть розкоментирована.
file1.txt
tab1 : \u2202
go\ home = just go home
message = Hello to \
Java \
Land
Test1:See if it works or not.
language : English
message1=Failed
path:c:\\wikipedia\\templates
! = : \\ \
# = : \\ \
! path:c:\\wikipedia\\templates \
website = https://ru.wikipedia.org/
key\ with\ spaces = This value bolongs to "key with spaces".package com.javarush.task.task20.task2003;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
/* c:\java\file1.txt
Знакомство с properties
*/
public class Solution {
public static Map<String, String> properties = new HashMap<>();
public void fillInPropertiesMap() throws Exception {
//implement this method - реализуйте этот метод
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
InputStream file = new FileInputStream(reader.readLine());
reader.close();
load(file);
file.close();
}
public void save(OutputStream outputStream) throws Exception {
//implement this method - реализуйте этот метод
for(Map.Entry<String, String> str: properties.entrySet()){
//String line = str.getKey() + ":" + str.getValue() + "\n";
String line = "";
String key, value;
if(str.getKey().contains(" ")) {
key = str.getKey().replace(" ", "\\ ");
} else { key = str.getKey(); }
if(str.getValue().contains("\\")){
value = str.getValue().replace("\\", "\\\\");
}else { value = str.getValue(); }
line = key + ":" + value + System.lineSeparator();
outputStream.write(line.getBytes());
}
}
public void load(InputStream inputStream) throws Exception {
//implement this method - реализуйте этот метод
byte[] buf = new byte[inputStream.available()];
inputStream.read(buf);
String temp = "";
for(int i=0; i < buf.length; i++){
temp = temp + (char) buf[i];
}
String[]content = temp.split(System.lineSeparator());
for(int i=0; i < content.length; i++){
if( !content[i].trim().equals("") ) {
if ( !content[i].substring(0, 1).equals("!") && !content[i].substring(0, 1).equals("#") ) {
if (content[i].trim().charAt(content[i].length() - 1) == '\\') {
content[i + 1] = content[i].substring(0, content[i].length() - 1) + content[i + 1].trim();
content[i] = "";
}
}
}
}
for(int i=0; i < content.length; i++){
String[] s1;
if( !content[i].trim().equals("") ) {
if( !content[i].substring(0,1).equals("!") && !content[i].substring(0,1).equals("#") ) {
if (content[i].indexOf('=') == -1) {
s1 = content[i].split(":", 2);
if(s1[0].contains("\\ ")) { s1[0] = s1[0].replace("\\ ", " "); }
if(s1[1].contains("\\\\")) { s1[1] = s1[1].replace("\\\\", "\\"); }
// if(s1[1].contains("\\u")) { s1[1] = (char) s1[1]; }
} else {
s1 = content[i].split("=", 2);
if(s1[0].contains("\\ ")) { s1[0] = s1[0].replace("\\ ", " "); }
if(s1[1].contains("\\\\")) { s1[1] = s1[1].replace("\\\\", "\\"); }
}
if(properties.containsKey(s1[0].trim())){
properties.replace(s1[0].trim(), s1[1].trim());
}
// properties.put(s1[0].trim(), s1[1].trim());
}
}
}
}
public static void main(String[] args) throws Exception {
/*
Solution obj = new Solution();
properties.put("Test", "1");
properties.put("language", "1");
properties.put("go home", "1");
properties.put("website", "1");
properties.put("message", "1");
properties.put("key with spaces", "1");
properties.put("path", "na");
properties.put("tab", "\u2205");
properties.put("tab1", "∂");
// System.out.println("Original: ");
for(Map.Entry<String, String> temp: properties.entrySet()){
System.out.println(temp.getKey() + " = " + temp.getValue());
}
obj.fillInPropertiesMap(); // c:\java\file1.txt
System.out.println("After loading: ");
for(Map.Entry<String, String> temp: properties.entrySet()){
System.out.println(temp.getKey() + " = " + temp.getValue());
}
/*
String fun = properties.get("tab").trim();
System.out.println("tab: " + fun);
char funchar = '\u2202';
String funstr = "\u2202";
System.out.println("Compare fun and funstr: " + fun.equals(funstr));
System.out.println("Fun char: " + funchar);
System.out.println("Fun string: " + funstr);
// System.out.println(fun.equals(properties.get("rab")));
System.out.println("\\u2202= " + "\u2202");
int c2 = 2202;
String symbol = "\\u" + c2;
System.out.println("Symbol: " + symbol);
char c1 = 0x2202;
System.out.println("C1: " + c1);
obj.save(new FileOutputStream("c:\\java\\file2.txt"));
*/
}
}
//c:\java\file1.txt