import java.io.IOException;
import java.util.Properties;
public class PropertyUtil {
public static void main(String[] args) {
Properties properties = new Properties();
try {
properties.load(PropertyUtil.class.getClassLoader().getResourceAsStream("LYZ.properties"));
String username = properties.getProperty("username");
System.out.println(username);
} catch (IOException e) {
System.out.println("無法讀取LYZ.properties");
}
}
}
控制臺信息
Exception in thread "main" java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:434)
at java.util.Properties.load0(Properties.java:353)
at java.util.Properties.load(Properties.java:341)
at com.test.PropertyUtil.main(PropertyUtil.java:10)
第十行代碼就是:
properties.load(PropertyUtil.class.getClassLoader().getResourceAsStream("LYZ.properties"));
添加回答
舉報
0/150
提交
取消