Reads a property list (key and element pairs) from the input character stream in a simple line-oriented format.
Program
package com.candidjava;
import java.io.IOException;
import java.io.StringReader;
import java.util.Properties;
/*
* @author : Mohan
* @description : The java.util.Properties.load(Reader reader) method Reads a property list (key and element pairs) from the input character stream in a simple line-oriented format.
*/
public class PropertiesLoadReader {
public static void main(String[] args) {
Properties prop = new Properties();
String s = "Length=200\nBreadth=15";
// create a new reader
StringReader reader = new StringReader(s);
try {
// load from input stream
prop.load(reader);
// print the properties list from System.out
prop.list(System.out);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Output
-- listing properties --
Length=200
Breadth=15
Explanation
Reads a property list (key and element pairs) from the input character stream in a simple line-oriented format.
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.