Created
February 13, 2016 09:58
-
-
Save Deivur/0f6da495ccda0f417703 to your computer and use it in GitHub Desktop.
Пример работы с классом Properties
This file contains hidden or 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
public class Solution { | |
public static Map<String, String> properties = new HashMap<>(); | |
public static Properties props = new Properties(); | |
public static void main (String[] args) throws Exception | |
{ | |
new Solution().fillInPropertiesMap(); | |
System.out.println(properties); | |
new Solution().save(new FileOutputStream("e:/f.properties")); | |
} | |
public void fillInPropertiesMap() throws Exception | |
{ | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); | |
InputStream fileProperties = new FileInputStream(bufferedReader.readLine()); | |
bufferedReader.close(); | |
load(fileProperties); | |
} | |
public void save(OutputStream outputStream) throws Exception { | |
PrintWriter printWriter = new PrintWriter(outputStream); | |
if (props.size() > 0) | |
props.putAll(properties); | |
props.store(outputStream, ""); | |
printWriter.close(); | |
} | |
public void load(InputStream inputStream) throws Exception { | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); | |
props.load(inputStream); | |
Set<String> list = props.stringPropertyNames(); | |
for (String current : list) | |
properties.put(current, props.getProperty(current)); | |
bufferedReader.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment