The Properties file
The Java properties files are normal text files that serve as a simple configuration tool. These files can be saved under any name. The file extension is. Properties.
example
# comment
to the file! Also comment
port number 3128
hostname = host such
language: de
long text This text \\
is longer than one line
to the file! Also comment
port number 3128
hostname = host such
language: de
long text This text \\
is longer than one line
There are 3 ways to keys, values and normal values entered.
- with blanks, the amount of space does not matter. As in the example above, the key "port number" and the value "3128".
- with equal sign, the number of spaces is immaterial. Just as in the example above, "hostname" and "such host"
- with a colon, here too the number of spaces does not matter
plays the text on the next line to continue, you can create a line break with the following symbol : \\
call in Java code
The following code retrieves the Properties File "beispiel.properties" on. After that, from this file, the value "hostname" is read.
property String file = "beispiel.properties";
Properties prop = new Properties ();
try {
prop.load (new FileInputStream (property file));
/ / Properties File Load
} catch (IOException e)
{/ / If the load failed
}
prop.getProperty String = hostname ("hostname");
Wikipedia - Java properties file
Properties prop = new Properties ();
try {
prop.load (new FileInputStream (property file));
/ / Properties File Load
} catch (IOException e)
{/ / If the load failed
}
prop.getProperty String = hostname ("hostname");
0 comments:
Post a Comment