Created
September 14, 2018 12:56
-
-
Save Maxomax/ec02213fb05be4b61dad7940fa08c75a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task20.task2003; | |
import java.io.*; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Properties; | |
/* | |
Знакомство с properties | |
В методе fillInPropertiesMap считайте имя файла с консоли и заполни карту properties данными из файла. | |
Про .properties почитать тут - http://ru.wikipedia.org/wiki/.properties | |
Реализуй логику записи в файл и чтения из файла для карты properties. | |
*/ | |
public class Solution { | |
public static Map<String, String> properties = new HashMap<>(); | |
public void fillInPropertiesMap() { | |
//implement this method - реализуйте этот метод | |
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
FileInputStream inputStream = new FileInputStream(reader.readLine())) { | |
load(inputStream); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public void save(OutputStream outputStream) throws Exception { | |
//implement this method - реализуйте этот метод | |
Properties propertiesSave = new Properties(); | |
if (!properties.isEmpty()) { | |
for (Map.Entry entry : properties.entrySet()) { | |
propertiesSave.setProperty(entry.getKey().toString(), entry.getValue().toString()); | |
} | |
} | |
propertiesSave.store(outputStream, null); | |
outputStream.close(); | |
} | |
public void load(InputStream inputStream) throws Exception { | |
//implement this method - реализуйте этот метод | |
Properties propertiesLoad = new Properties(); | |
propertiesLoad.load(inputStream); | |
for (final String name : propertiesLoad.stringPropertyNames()) { | |
properties.put(name, propertiesLoad.getProperty(name)); | |
} | |
inputStream.close(); | |
} | |
public static void main(String[] args) { | |
} | |
} | |
/*Требования: | |
1. Метод fillInPropertiesMap должен считывать данные с консоли. | |
2. Метод fillInPropertiesMap должен создавать FileInputStream, передавая считанную строку в качестве параметра. | |
3. Метод fillInPropertiesMap должен вызывать метод load передавая только что созданный FileInputStream в качестве параметра. | |
4. Метод save должен сохранять карту properties в полученный в качестве параметра объект типа OutputStream. | |
5. Метод load должен восстанавливать состояние карты properties из полученного в качестве параметра объекта типа InputStream.*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment