如果在Java中使用ResourceBundle時(shí),緩存更新無效,可以嘗試以下解決方法:
ResourceBundle.clearCache();
ResourceBundle bundle = ResourceBundle.getBundle("MyResources", new Control() {
@Override
public long getTimeToLive(String baseName, Locale locale) {
// 禁用緩存
return TTL_DONT_CACHE;
}
});
ClassLoader classLoader = new URLClassLoader(new URL[]{new File("path/to/resources").toURI().toURL()});
ResourceBundle bundle = ResourceBundle.getBundle("MyResources", Locale.getDefault(), classLoader);
通過以上方法,您應(yīng)該能夠解決Java中ResourceBundle緩存更新無效的問題。