你的代码中好像并没有去找属性文件呀。如果你没有别的代码的话。
属性文件应该跟Untitled1.class放在同一个目录下,如果Untitled1.clss属于某一个包,则要将属性文件放在包的起始目录下。且Classpath中要有加上.;(代表当前目录).
属性文件应该跟Untitled1.class放在同一个目录下,如果Untitled1.clss属于某一个包,则要将属性文件放在包的起始目录下。且Classpath中要有加上.;(代表当前目录).
解决方案 »
- 高分问一个双缓冲的问题
- 时间的怪问题???
- 错误 求改进
- 哪位大哥大姐能帮我解答一下啊,为什么表格内容显示不出来啊!!!
- 请教线程问题,怎样才能在一个线程里面等待另外一个线程执行以后,自己再执行呢?
- 十在是不明白了请教
- 一条基础题目,还是不太懂底层的东西
- 为什么会这样?
- -------怎么办?
- 在<textarea>中输入的字符串 getString 是有换行符的,但用sendmail发送这个getString 后,在邮件中显示的这个字符串里的所有换行符全不
- 通过(sax或者dom)解析以下XML文件(见文章),用swing或swt动态生成用户界面(有难度,是高手的能否给出代码!)
- java.util.ResourceBundle 和java.util.properties 这两个类有什么区别?
上面代码路径没改好,应该是这个:
public class Untitled1 {
public static void main(String[] args) {
ResourceBundle messages = ResourceBundle.getBundle("untitled");
String message = messages.getString("greetings"); System.out.println(message);
}
}
而不是跟java文件放在一个目录下
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader. Calling this method is equivalent to calling
getBundle(baseName, Locale.getDefault(), this.getClass().getClassLoader()),
except that getClassLoader() is run with the security privileges of ResourceBundle. See getBundle for a complete description of the search and instantiation strategy. Parameters:
baseName - the base name of the resource bundle, a fully qualified class name
FileInputStream fis = new FileInputStream(propertyFile);
Properties mProperties = new Properties();
mProperties.load(fis); //属性信息与文件内容帮邦定
fis.close();2.保存属性文件可以利用:
mProperties.store(FileOutputStream file,String header);
使用FileInputStream 和Properties的load功能,看楼主的配置文件在系统中是怎么个处理法了。
public class Untitled1 {
public static void main(String[] args) {
ResourceBundle messages = ResourceBundle.getBundle("mesages");
String message = messages.getString("greetings"); System.out.println(message);
}
}
资源文件命名和读取顺序如下:
filename_contry_language_x.properties
filename_contry_language.properties
filename_contry.properties
filename.properties首先,getBundle("message")里面的message应该换成“filename”
getString("greetings")里面的greetings应该写成filename.value value即你需要读取的那个key
楼主把Locale设置成Locale.ENGLISH,就能运行了,有空我会给你个例子的