Skip to content

Instantly share code, notes, and snippets.

@Deivur
Created February 13, 2016 09:58
Show Gist options
  • Save Deivur/0f6da495ccda0f417703 to your computer and use it in GitHub Desktop.
Save Deivur/0f6da495ccda0f417703 to your computer and use it in GitHub Desktop.
Пример работы с классом Properties
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