当前位置: 技术问答>java相关
Properties的小小小问题,请指教!!!
来源: 互联网 发布时间:2014-12-28
本文导语: class properties{ public static void main(String args[])throws Exception { Properties params = new Properties(); params.load(new FileInputStream(args[0])); System.out.println(params.getProperty("hello")); } } 请问如何才能运行这个程序! args[0]是...
class properties{
public static void main(String args[])throws Exception
{
Properties params = new Properties();
params.load(new FileInputStream(args[0]));
System.out.println(params.getProperty("hello"));
}
}
请问如何才能运行这个程序!
args[0]是不是扩展名为:properties的文件,文件中的内容应如何写才
符合查询要求!
|
Reads a property list (key and element pairs) from the input stream. The stream is assumed to be using the ISO 8859-1 character encoding. Every property occupies one line of the input stream. Each line is terminated by a line terminator (n or r or rn). Lines from the input stream are processed until end of file is reached on the input stream. A line that contains only whitespace or whose first non-whitespace character is an ASCII # or ! is ignored (thus, # or ! indicate comment lines). Every line other than a blank line or a comment line describes one property to be added to the table (except that if a line ends with , then the following line, if it exists, is treated as a continuation line, as described below). The key consists of all the characters in the line starting with the first non-whitespace character and up to, but not including, the first ASCII =, :, or whitespace character. All of the key termination characters may be included in the key by preceding them with a . Any whitespace after the key is skipped; if the first non-whitespace character after the key is = or :, then it is ignored and any whitespace characters after it are also skipped. All remaining characters on the line become part of the associated element string. Within the element string, the ASCII escape sequences t, n, r, \, ", ', (a backslash and a space), and uxxxx are recognized and converted to single characters. Moreover, if the last character on the line is , then the next line is treated as a continuation of the current line; the and line terminator are simply discarded, and any leading whitespace characters on the continuation line are also discarded and are not part of the element string. As an example, each of the following four lines specifies the key "Truth" and the associated element value "Beauty":
Truth = Beauty
Truth:Beauty
Truth :Beauty
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 whitespace on the continuation line are merely discarded and are not replaced by one or more other characters. As a third example, the line: cheeses
specifies that the key is "cheeses" and the associated element is the empty string.
--
如果你试着先看一下api文档的话 ...
Truth = Beauty
Truth:Beauty
Truth :Beauty
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 whitespace on the continuation line are merely discarded and are not replaced by one or more other characters. As a third example, the line: cheeses
specifies that the key is "cheeses" and the associated element is the empty string.
--
如果你试着先看一下api文档的话 ...
|
是的,格式是linux下config格式即:
#content
name=value
name1=value1
...
#content
name=value
name1=value1
...