Java Properties 文件书写规范

12 篇文章 0 订阅

Java 程序支持国际化和本地化的发布,通常我们通过书写 Java Properties 文件来实现,原则上,书写都很随意,但其实还是有一些规则在里面,只是平时没太在意,特总结如下:

常用规范

The properties files read by Nucleus must follow a format that is recognized by the classjava.util.Properties. The rules for the format are as follows:

Nucleus properties files also use several special properties types, indicated by a leading $ character.

特殊变量

Nucleus properties files use several special properties that are indicated by a leading $ character:

$class

The component’s Java class.

$scope

The scope of the component (global, session, or request). The default value is global. See theComponent Scopes section in this chapter.

$description

A brief description of the component, for display in the ATG Control Center Components task areas.

You can set the $scope and $description properties 

实例特殊说明

Each line in a .properties file normally stores a single property. Several formats are possible for each line, includingkey=value, key = value, key:value, and key value. Note that single-quotes or double-quotes are considered part of the string. Trailing space is significant and presumed to be trimmed as required by the consumer.

Comment lines in .properties files are denoted by thenumber sign (#) or the exclamation mark (!) as the first non blank character, in which all remaining text on that line is ignored. The backwards slash is used to escape a character. An example of a properties file is provided below.

# You are reading the ".properties" entry.
! The exclamation mark can also mark text as comments.
# The key and element characters #, !, =, and : are written with
# a preceding backslash to ensure that they are properly loaded.
website = http\://en.wikipedia.org/
language = English
# The backslash below tells the application to continue reading
# the value onto the next line.
message = Welcome to \
          Wikipedia!
# Add spaces to the key
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
# Unicode
tab : \u0009

In the example above, website would be a key, and its corresponding value would behttp://en.wikipedia.org/. While the number sign (#) and the exclamation mark (!) marks text as comments, it has no effect when it is part of a property. Thus, the keymessage has the value Welcome to Wikipedia! and not Welcome to Wikipedia. Note also that all of the whitespace in front of Wikipedia! is excluded completely.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值