读取配置文件 Java ResourceBundle

新建文件 TimeConfig.properties:

# 最新任务时间
topic.recent.time=10-22 00:01

创建TimeConfig类:

public class TimeConfig{
    
    
    static ResourceBundle resourceBundle;

    static {
    
    
        try {
    
    
            resourceBundle = ResourceBundle.getBundle("config/TopicTimeConfig");
        } catch (Exception e) {
    
    
            e.printStackTrace();
        }
    }
    public static String getTime() {
    
    
        return resourceBundle.getString("topic.recent.time");
    }
}

调用

    String da = resourceBundle.getString("topic.recent.time");
    或
    TimeConfig.getTime();

猜你喜欢

转载自blog.csdn.net/Ciel_Y/article/details/110233781