Given the content of /resourses/Message.properties:

welcome1="Good day!"

and given the code fragment:

Properties prop = new Properties();
FileInputStream fis = new FileInputStream("/resources/Message.properties");
prop.load(fis);
System.out.println(prop.getProperty("welcome1"));
System.out.println(prop.getProperty("welcome2", "Test"));//line n1
System.out.println(prop.getProperty("welcome3"));

What is the result?

A.

Good day!
Test

followed by an Exception stack trace
B.

Good day!

followed by an Exception stack trace
C.

Good day!
Test
null

D. A compilation error occurs at line n1.

题解

程序第 13 行,会输出「/resourses/Message.properties」中「welcome1」键值所对应的值,即为「Good day!」。

程序第 14 行,由于「/resourses/Message.properties」中不存在「welcome2」键值,但有设置默认值「Test」,所以会输出默认值「Test」。

程序第 15 行,由于「/resourses/Message.properties」中不存在「welcome3」键值,所以输出「null」。