📌  相关文章
📜  Java中的 LogRecord getResourceBundle() 方法及示例

📅  最后修改于: 2022-05-13 01:55:21.749000             🧑  作者: Mango

Java中的 LogRecord getResourceBundle() 方法及示例

Java.lang.reflect.LogRecordgetResourceBundle()方法用来获取本地化资源包。资源包用来本地化这个LogRecord的消息。

句法:

public ResourceBundle getResourceBundle()

参数:此方法不接受任何内容。

返回:此方法返回本地化资源包

下面的程序说明了 getResourceBundle() 方法:
方案一:

// Java program to illustrate
// getResourceBundle() method
  
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.ResourceBundle;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("800"),
            "Hi Logger");
  
        logRecord
            .setResourceBundle(
                ResourceBundle
                    .getBundle("myResource"));
  
        // get ResourceBundle
        ResourceBundle resourceBundle
            = logRecord.getResourceBundle();
  
        // print the ResourceBundle details
        System.out.println(
            "Resource Bundle = "
            + resourceBundle.getBaseBundleName());
    }
}
输出:
Resource Bundle = myResource

方案二:

// Java program to illustrate
// getResourceBundle() method
  
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.ResourceBundle;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Create LogRecord object
        LogRecord logRecord = new LogRecord(
            Level.parse("600"),
            "GFG Logger");
        logRecord.setResourceBundle(null);
  
        // get ResourceBundle
        ResourceBundle resourceBundle
            = logRecord.getResourceBundle();
  
        // print the ResourceBundle details
        System.out.println(
            "Resource Bundle = "
            + resourceBundle);
    }
}
输出:
Resource Bundle = null

参考资料: https: Java/util/logging/LogRecord.html#getResourceBundle()