Guest User

Untitled

a guest
Jun 18th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package prop;
  2.  
  3. import java.util.Locale;
  4. import java.util.ResourceBundle;
  5.  
  6. public class ReadDate {
  7.  
  8. public static void main(String[] args) {
  9.  
  10. /*
  11. * 错误的做法, prop资源文件相当于一个对象, 可以通过类装载器在classpath中找到, 因此需要提供类全名
  12. */
  13. //ResourceBundle bundle = ResourceBundle.getBundle("test.properties");
  14.  
  15. /*
  16. * 相当于ResourceBundle.getBundle("prop.test", new Locale("zh", "CN"), ReadDate.class.getClassLoader());
  17. */
  18. //ResourceBundle bundle = ResourceBundle.getBundle("prop.test"); //success
  19.  
  20. /*
  21. * 推荐
  22. */
  23. //ResourceBundle bundle = ResourceBundle.getBundle("prop.test", new Locale("zh", "CN")); //success
  24. ResourceBundle bundle = ResourceBundle.getBundle("prop.test", new Locale("en", "US"), ReadDate.class.getClassLoader()); //success
  25.  
  26. System.out.println(bundle.getString("username"));
  27. }
  28. }
Add Comment
Please, Sign In to add comment