當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java LogRecord setResourceBundle()用法及代碼示例


java.util.logging.LogRecord的setResourceBundle()方法用於設置本地化資源包。資源包用於本地化此LogRecord的消息。

用法:

public void setResourceBundle(ResourceBundle bundle)

參數:此方法接受為本地化包的包,它可以為null。


返回:此方法不返回任何內容。

以下示例程序旨在說明setResourceBundle()方法:
示例1:

// 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

示例2:

// 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://docs.oracle.com/javase/8/docs/api/java/util/logging/LogRecord.html#setResourceBundle(java.util.ResourceBundle)



相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 LogRecord setResourceBundle() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。