I am currently working on a project in which many options should be saved.
- How are options normally saved?
- What are best practices when saving/loading settings?
I am currently working on a project in which many options should be saved.
您可以使用.properties
文件来存储配置,通常那些用于存储环境配置。如果这就是你所说的。
查看有关该文件的文档;这也可以是一个例子
String path = servletContext.getRealPath(propertiesFilePath);
Properties prop = new Properties();
try {
prop.load(new FileInputStream(path));
} catch (Exception e) {
// handle
}
String name = prop.getProperty("name");
如果应该存储和维护用户特定的配置,您可以为此使用Preferences API 。
应用程序需要偏好和配置数据以适应不同用户和环境的需求。java.util.prefs 包为应用程序提供了一种存储和检索用户和系统首选项和配置数据的方法。数据永久存储在依赖于实现的后备存储中。有两个独立的偏好节点树,一个用于用户偏好,一个用于系统偏好。