java.util.ResourceBundle.clearCache(ClassLoader loader)%uA0方法从已经使用给定的类加载器加载的缓存中移除所有资源包。
声明
以下是java.util.ResourceBundle.clearCache()方法的声明
public static final void clearCache(ClassLoader loader)
参数
-
loader%uA0-- 类加载器
返回值
此方法不返回任何值。
异常
-
NullPointerException%uA0-- 如果%uA0loader 为%uA0null
例子
下面的示例演示java.util.ResourceBundle.clearCache()方法的用法。
package com.yiibai 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.") } }
假设有一个资源文件%uA0hello_en_US.properties%uA0可以你的 CLASSPATH中访问, 以下内容。该文件将被用作输入到示例程序:
hello=Hello World!
让我们来编译和运行上面的程序,这将产生以下结果:
Hello World! Clearing Cache... Cache Cleared.