Properties are processed in terms of lines. There are two kinds of line, natural lines and logical lines. A natural line is defined as a line of characters that is terminated either by a set of line terminator characters (\n or \r or \r\n) or by the end of the stream. A natural line may be either a blank line, a comment line, or hold all or some of a key-element pair. A logical line holds all the data of a key-element pair, which may be spread out across several adjacent natural lines by escaping the line terminator sequence with a backslash character \. Note that a comment line cannot be extended in this manner; every natural line that is a comment must have its own comment indicator, as described below. Lines are read from input until the end of the stream is reached.
As another example, the following three lines specify a single property:
fruits apple, banana, pear, \
cantaloupe, watermelon, \
kiwi, mango
The key is "fruits" and the associated element is:
"apple, banana, pear, cantaloupe, watermelon, kiwi, mango"
Note that a space appears before each \ so that a space will appear after each comma in the final result; the \, line terminator, and leading white space on the continuation line are merely discarded and are not replaced by one or more other characters.
from : http://download.oracle.com/javase/6/docs/api/java/util/Properties.html
本文详细介绍了Properties文件中自然线与逻辑线的概念,解释了如何从输入中读取直至达到流的结束,以及如何处理包含多个元素的键值对。
2899

被折叠的 条评论
为什么被折叠?



