Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package prop;
- import java.util.Locale;
- import java.util.ResourceBundle;
- public class ReadDate {
- public static void main(String[] args) {
- /*
- * 错误的做法, prop资源文件相当于一个对象, 可以通过类装载器在classpath中找到, 因此需要提供类全名
- */
- //ResourceBundle bundle = ResourceBundle.getBundle("test.properties");
- /*
- * 相当于ResourceBundle.getBundle("prop.test", new Locale("zh", "CN"), ReadDate.class.getClassLoader());
- */
- //ResourceBundle bundle = ResourceBundle.getBundle("prop.test"); //success
- /*
- * 推荐
- */
- //ResourceBundle bundle = ResourceBundle.getBundle("prop.test", new Locale("zh", "CN")); //success
- ResourceBundle bundle = ResourceBundle.getBundle("prop.test", new Locale("en", "US"), ReadDate.class.getClassLoader()); //success
- System.out.println(bundle.getString("username"));
- }
- }
Add Comment
Please, Sign In to add comment