Java.util.ResourceBundle.clearCache() 方法
描述
java.util.ResourceBundle.clearCache(ClassLoader loader) 方法从缓存中删除所有使用给定类加载器加载的资源包。
声明
以下是 java.util.ResourceBundle.clearCache() 方法的声明
public static final void clearCache(ClassLoader loader)
参数
loader − 类加载器
返回值
此方法不返回值。
异常
NullPointerException − 如果加载器为 null
示例
下面的例子展示了 java.util.ResourceBundle.clearCache() 方法的使用。
package com.tutorialspoint;
import java.util.Locale;
import java.util.ResourceBundle;
public class ResourceBundleDemo {
public static void main(String[] args) {
// create a new ResourceBundle with specified locale
ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US);
// print the text assigned to key "hello"
System.out.println("" + bundle.getString("hello"));
// clear the cache by using system classloader
ClassLoader cl = ClassLoader.getSystemClassLoader();
System.out.println("Clearing Cache...");
ResourceBundle.clearCache(cl);
System.out.println("Cache Cleared.");
}
}
假设我们在您的 CLASSPATH 中有一个可用的资源文件 hello_en_US.properties,其内容如下。 该文件将用作我们示例程序的输入 −
hello = Hello World!
让我们编译并运行上面的程序,这将产生以下结果 −
Hello World! Clearing Cache... Cache Cleared.

