写了以下这个有关ResourceBundle读取的小程序,本意是读取第一个bundle,打印相关信息;然后再读取第二个bundle,也打印相关信息。但是结果表现为仅第二个bundle的信息被读取,第一个bundle未能读入。希望高手能给指点一二,不胜感激. --------------------------------------------------- package testBean; import java.util.MissingResourceException; import java.util.ResourceBundle; public class testBundle{ private static final String NAME = "name#"; private static final String CATEGORY = "category#"; public static void main(String[] args){ new testBundle(); } public testBundle(){ System.out.println("initialTest"); //debug时发现以下该行未能执行,且不断重复运行上面的一行打印语句 read(ResourceBundle.getBundle(testBundle.class.getName())); String classPackage = testBundle.class.getName(); classPackage = classPackage.substring(0, classPackage.lastIndexOf(".")); read(ResourceBundle.getBundle(classPackage + ".testBundle2")); } private void read(ResourceBundle resource){ System.out.println("initialReadTest"); for(int i = 1; ; i++){ String name = null; try{ name = resource.getString(NAME + i); System.out.println("Node Name: " + name); }catch(MissingResourceException ex){ //Stop the loop when this node does not exist. break; } String category = resource.getString(CATEGORY + i); System.out.println("Category Name: " + category); } } } --------------------------------------- 执行结果为"initialTest"被打印了316行(实在弄不清楚是哪里出了问题...) testBundle不能被读取 testBundle2可以被读取,但是被重复读取了n次 我的开发环境: Windows XP JDK 1.6.0 Eclipse 3.2.2
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货