首页 > Linux操作系统 > Linux操作系统 > Java属性文件的读取
方法 一
InputStream in = lnew BufferedInputStream( new FileInputStream(name));
Properties p = new Properties();
p.load(in);
注意路径的问题,做执行之后就可以调用p.getProperty("name")得到对应属性的值
方法二
Locale locale = Locale.getDefault();
ResourceBundle localResource = ResourceBundle.getBundle("test/propertiesTest", locale);
String value = localResource.getString("test");
System.out.println("ResourceBundle: " + value);
工程src目录下propertiesTest.properties(名字后缀必须为properties)文件内容如下:
test=hello word
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/81227/viewspace-701050/ ,如需转载,请注明出处,否则将追究法律责任。