ResourceBundle和Properties
项目需要从绝对路径中取的页面label的value
1.用ResourceBundle取值
public static void main(String args) throws MalformedURLException {
String resourcePath = "D:/";
String resourceFileName = "test";
Locale currentLocale = Locale.getDefault();
File resourceFile = new File(resourcePath);
URL resourceUrl = resourceFile .toURI().toURL();
URL urls = {resourceUrl };
ClassLoader loader = new URLClassLoader(urls);
ResourceBundle bundle = ResourceBundle.getBundle(resourceFileName, currentLocale, loader);
System.out.println(bundle.getString("viewRatings"));
}
-
直接IO读取properties文件 public static void main(String args) throws FileNotFoundException, IOException { InputStream is = new FileInputStream(new File("D:/test.properties")); Properties p = new Properties(); p.load(is);
System.out.println(p.get("viewRatings"));}