문제

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?
도움이 되었습니까?

해결책 2

You can use the Preferences API for this if it is user specific configuration that should be stored and maintained.

Applications require preference and configuration data to adapt to the needs of different users and environments. The java.util.prefs package provides a way for applications to store and retrieve user and system preference and configuration data. The data is stored persistently in an implementation-dependent backing store. There are two separate trees of preference nodes, one for user preferences and one for system preferences.

다른 팁

You could use .properties files to store configurations, usually those are used to store environment configurations. If this is what you're talking about.

Have a look at the documentation about that; also this could be an example

String path = servletContext.getRealPath(propertiesFilePath);            
Properties prop = new Properties();         
try {           
    prop.load(new FileInputStream(path));
} catch (Exception e) { 
    // handle      
}     
String name = prop.getProperty("name"); 

I recommend using java properties. Properties are configuration values managed as key/value pairs. It is possible to load/save properties from your program or edit the *.properties configuration files manually.

Documentation

Example

I hope this is what you call "settings"..

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top