读取配置文件properties工具类

我会带着你远行 2022-07-14 15:32 420阅读 0赞

package com.cmsz.rc.util;

import java.text.MessageFormat;
import java.util.Properties;

public class ConfigReaderUtil {

  1. /**
  2. * 配置属性
  3. */
  4. private static Properties properties;
  5. public static String getProperties(String key) {
  6. String tempStr = String.valueOf(properties.get(key));
  7. if (null != tempStr && !tempStr.isEmpty()) {
  8. return tempStr;
  9. } else {
  10. return "";
  11. }
  12. }
  13. public static String getProperties(String key, Object... strs) {
  14. String tempStr = String.valueOf(properties.get(key));
  15. if (null != tempStr && !tempStr.isEmpty()) {
  16. if (strs != null && strs.length > 0) {
  17. return MessageFormat.format(tempStr, (Object[]) strs);
  18. } else {
  19. return tempStr;
  20. }
  21. } else {
  22. return "";
  23. }
  24. }
  25. public static Properties getProperties() {
  26. return properties;
  27. }
  28. public static void setProperties(Properties properties) {
  29. ConfigReaderUtil.properties = properties;
  30. }
  31. /**
  32. * 私有的构造函数
  33. */
  34. private ConfigReaderUtil() {
  35. }

}

发表评论

表情:
评论列表 (有 0 条评论,420人围观)

还没有评论,来说两句吧...

相关阅读