.properties文件的格式

1.说明: 这种文件需要有一定的格式才能被java.util.Properties包读取。主要用在java相关的技术上,用来存储应用的可配置参数。

  • 每个实体都占一行,有如下两种格式。两个字符串参数,左边是键,右边是值。
    1)propertyName=propertyValue
    2)propertyName:propertyValue
  • 在键与值之间的空格会被忽略。下面两个是等效的。
    name=Stephen
    name = Stephen
    且在每一行的开始部分空格也会被忽略。
  • 注释用 # 号或 ! 号开始,会被忽略。且空白行也会被忽略。
  • 值一般会处于行的末尾部分,末尾如有空格,也包括在值里。
  • 续行符,\ + 换行符
  message = Welcome to \
                     Wikipedia!

等同于 message = Welcome to Wikipedia!
注意:每一行的开始部分空格也会被忽略

  • 转义字符,\ \表示\,\n表示换行,\r 表示carriage return,\t表示tab
  • 使用Unicode,\u开头,比如,\u002c

2.例子: CSDN不支持properties格式代码块,我用Typora软件编辑markdown的话支持。

# You are reading the ".properties" entry.
! The exclamation mark can also mark text as comments.
# The key characters =, and : should be written with
# a preceding backslash to ensure that they are properly loaded.
# However, there is no need to precede the value characters =, and : by a backslash.
website = https://en.wikipedia.org/
language = English
# The backslash below tells the application to continue reading
# the value onto the next line.
message = Welcome to \
          Wikipedia!
# But if the number of backslashes at the end of the line is even, the next line is not included in the value. In the following example, the value for "key" is "valueOverOneLine\"
key = valueOverOneLine\\
# This line is not included in the value for "key"
# Add spaces to the key
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
# The characters = and : in the key must be escaped as well:
key\:with\=colonAndEqualsSign = This is the value for the key "key:with=colonAndEqualsSign"
# Unicode
tab : \u0009
# If you want your property to include a backslash, it should be escaped by another backslash
path=c:\\wiki\\templates
# However, some editors will handle this automatically

3.参考文章:
1.https://en.wikipedia.org/wiki/.properties
2.ATG Programming Guide:Properties File Format

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值