java properties书写_Java Properties 文件书写规范

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

常用规范

Entries are generally expected to be a single line of the form, one of the following:

propertyName=propertyValue

propertyName:propertyValue

White space that appears between the property name and property value is ignored, so the following are equivalent.

name=Stephen

name = Stephen

White space at the beginning of the line is also ignored.

A property value can span several lines if each line is terminated by a backslash (‘\’) character. For example:

targetCities=\

Detroit,\

Chicago,\

Los Angeles

This is equivalent to targetCities=Detroit,Chicago,Los Angeles (white space at the beginning of lines is ignored).

The characters newline, carriage return, and tab can be inserted with characters \n, \r, and \t, respectively.

The backslash character must be escaped as a double backslash. For example:

path=c:\\docs\\doc1

Note: It is not necessary to escape backslashes in property values when you use the ATG Control Center Components window; the ATG Control Center handles the escape characters automatically.

Nucleus properties files also use several special properties types, 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.

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.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值