Java读取Properties文件有以下六种方法:
1。使用java.util.Properties类的load()方法String fileName="E:/system.properties";
InputStream in = new BufferedInputStream(new FileInputStream(fileName));
Properties p = new Properties();
p.load(in);
System.out.println(p);
2。使用java.util.ResourceBundle类的getBundle()方法ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());
ResourceBundle提供软件国际化的捷径,这个类的作用一般是用来读取资源属性文件(properties),然后根据.properties文件的名称信息(本地化信息),匹配当前系统的国别语言信息(也可以程序指定),然后获取相应的properties文件的内容。
注意:,这个properties文件的名字是有规范的:一般的命名规范是: 自定义名_语言代码_国别代码.properties,
如果是默认的,直接写为:自定义名.properties
比如:
myres_en_US.properties
myres_zh_CN.properties
myres.properties
当在中文操作系统下,如果myres_zh_CN.properties、myres.properties两个文件都存在,则优先会使用m