hutool.setting.props

Properties文件工具类

Module Contents

Classes

PropsUtil

Properties文件工具类

API

class hutool.setting.props.PropsUtil

Properties文件工具类

加载和解析标准 .properties 格式的配置文件。

static load(path: str, charset: str = 'utf-8') dict

加载.properties文件

支持的格式:
  • key=value

  • key: value

  • key value

  • # 注释行

  • ! 注释行

  • 续行符(行尾 )

参数:
  • path – .properties文件路径

  • charset – 文件编码,默认为 ‘utf-8’

返回:

解析后的属性字典

static get(props: dict, key: str, default: Any = None) Any

获取属性值

参数:
  • props – 属性字典

  • key – 属性键

  • default – 默认值

返回:

属性值,不存在时返回默认值

static _unescape(value: str) str

反转义properties值中的特殊字符

参数:

value – 原始值

返回:

反转义后的值

static create() dict

创建空属性字典

返回:

空字典

static store(props: dict, path: str, charset: str = 'utf-8', comment: str = '') None

将属性字典持久化到.properties文件

参数:
  • props – 属性字典

  • path – 文件路径

  • charset – 文件编码

  • comment – 文件头部注释

static to_dict(props: dict) dict

转为普通字典

参数:

props – 属性字典

返回:

字典副本