Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 资源包_Java_Internationalization_Properties - Fatal编程技术网

Java 资源包

Java 资源包,java,internationalization,properties,Java,Internationalization,Properties,我只是从这个开始,用这个代码: public static void main(String[] args) { Locale[] supportedLocales = { new Locale("en", "CA"), new Locale("es", "ES") }; ResourceBundle labels = ResourceBundle.getBundle("Messages", supportedLocales[0]); System.out.

我只是从这个开始,用这个代码:

public static void main(String[] args) {
 Locale[] supportedLocales = {
      new Locale("en", "CA"),
      new Locale("es", "ES")

  };

 ResourceBundle labels = ResourceBundle.getBundle("Messages", supportedLocales[0]);
 System.out.println(supportedLocales[0].getDisplayVariant());
 System.out.println(supportedLocales[0].getVariant().toString());
}

}
Enumeration bundleKeys = labels.getKeys();

    while (bundleKeys.hasMoreElements()) {
        String key = (String)bundleKeys.nextElement();
        String value = labels.getString(key);
        System.out.println("key = " + key + ", " + 
                   "value = " + value);
    }  
我没有得到这两个
sysout
。在类路径中有以下文件:
消息。捆绑

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<f:loadBundle basename="Messages" var="msg"/>
<f:view> <html>
    <body>
        <f:view>
            <h:form>
                <h:commandButton value="#{msg.cancel}" action="fail"/>
                <h:commandButton value="#{msg.submit}" action="success"/>
                <h:outputText value="#{myBundle[myBean.msgKey]}"/>
            </h:form>  
        </f:view>
    </body>
</html> </f:view>
cancel=Cancelar
submit=Enviar
Search=Buscar

我只需要列举所有的键,这样我就可以读一个了。使用此代码:

public static void main(String[] args) {
 Locale[] supportedLocales = {
      new Locale("en", "CA"),
      new Locale("es", "ES")

  };

 ResourceBundle labels = ResourceBundle.getBundle("Messages", supportedLocales[0]);
 System.out.println(supportedLocales[0].getDisplayVariant());
 System.out.println(supportedLocales[0].getVariant().toString());
}

}
Enumeration bundleKeys = labels.getKeys();

    while (bundleKeys.hasMoreElements()) {
        String key = (String)bundleKeys.nextElement();
        String value = labels.getString(key);
        System.out.println("key = " + key + ", " + 
                   "value = " + value);
    }  
我得到这个输出:

key = Search, value = Buscar
key = submit, value = Enviar
key = cancel, value = Cancelar