db.hostname=localhost db.port=3306 db.name=mydatabase db.username=admin db.password=secret import com.github.smallerconfig.loader.PropertiesLoader; import com.github.smallerconfig.loader.LoaderManager; import com.github.smallerconfig.source.FileSource; public class DatabaseConnector { private String hostname; private int port; private String dbName; private String username; private String password; public DatabaseConnector() { PropertiesLoader loader = LoaderManager.getInstance().getLoader(); FileSource source = new FileSource("config.properties"); loader.load(source); this.hostname = loader.getValue("db.hostname"); this.port = Integer.parseInt(loader.getValue("db.port")); this.dbName = loader.getValue("db.name"); this.username = loader.getValue("db.username"); this.password = loader.getValue("db.password"); } } algorithm1.param1=10 algorithm1.param2=20 algorithm2.param1=30 algorithm2.param2=40 import com.github.smallerconfig.loader.PropertiesLoader; import com.github.smallerconfig.loader.LoaderManager; import com.github.smallerconfig.source.FileSource; public class AlgorithmLibrary { private int algorithm1Param1; private int algorithm1Param2; private int algorithm2Param1; private int algorithm2Param2; public AlgorithmLibrary() { PropertiesLoader loader = LoaderManager.getInstance().getLoader(); FileSource source = new FileSource("config.properties"); loader.load(source); this.algorithm1Param1 = Integer.parseInt(loader.getValue("algorithm1.param1")); this.algorithm1Param2 = Integer.parseInt(loader.getValue("algorithm1.param2")); this.algorithm2Param1 = Integer.parseInt(loader.getValue("algorithm2.param1")); this.algorithm2Param2 = Integer.parseInt(loader.getValue("algorithm2.param2")); } }


上一篇:
下一篇:
切换中文