Свойства Java широко используются как постоянный формат (файл), так и в памяти. Они также широко поддерживаются такими инструментами, как IDE, ant, maven и т. Д.
Класс Свойства очень прост в использовании и имеет несколько полезных методов для вашей цели (сохранение, загрузка и хранение):
Properties preferences = new Properties();
preferences.put("color", "red");
preferences.put("style", "bold");
preferences.store(new FileOutputStream("prefs.properties"), "preferences");
// reload the properties
Properties preferences = new Properties();
preferences.load(new FileInputStream("prefs.properties"));
Файл Java .properties выглядит следующим образом:
# You are reading the ".properties" entry.
! The exclamation mark can also mark text as comments.
website = http://en.wikipedia.org/
language = English
# The backslash below tells the application to continue reading
# the value onto the next line.
message = Welcome to \
Wikipedia!
# Add spaces to the key
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
# Unicode
tab : \u0009