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

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

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

Java.util.logging.LogRecordsetResourceBundle()方法是用来设置本地化资源包的。资源包用来本地化这个LogRecord的消息。

句法:

public void setResourceBundle(ResourceBundle bundle)

参数:此方法接受作为本地化捆绑包的捆绑包,它可能为空。

Return :此方法不返回任何内容。

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

// Java program to illustrate setResourceBundle() 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");
  
        // Create ResourceBundle using getBundle
        // myResource is a properties file
        ResourceBundle bundle
            = ResourceBundle
                  .getBundle("myResource");
  
        // set ResourceBundle
        logRecord.setResourceBundle(bundle);
  
        // print the ResourceBundle details
        System.out.println(
            "Resource Bundle = "
            + logRecord
                  .getResourceBundle()
                  .getBaseBundleName());
    }
}
输出:
Resource Bundle = myResource

方案二:

// Java program to illustrate setResourceBundle() 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");
  
        // Create ResourceBundle having null value
        ResourceBundle bundle
            = null;
  
        // set ResourceBundle
        logRecord.setResourceBundle(bundle);
  
        // print the ResourceBundle details
        System.out.println(
            "Resource Bundle = "
            + logRecord.getResourceBundle());
    }
}
输出:
Resource Bundle = null

参考资料: https: Java Java.util.ResourceBundle)