资源文件:res_en_US.properties,位置文件跟目录 内容如下: total=TOTALl add=ADD del=DEL view=VIEW 资源管理类,单例模式实现如下(不妥之处,还希望高手指正): import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.Properties; /** * 动态加载资源属性文件(资源文件更新,自动加载最新内容),单例模式 * * @author xiaoluozheng * */ public class ResManager { private String RES_NAME = "res_en_US.properties"; // 资源属性文件名称 private long lastModify = 0L; // 资源文件最近修改时间 private Properties prop = new Properties(); private static ResManager instance = new ResManager(); /** * 私有构造函数 */ private ResManager() { try { // 加载资源属性文件 File file = new File(RES_NAME); if (file.canRead()) { lastModify = file.lastModified(); InputStream inputStream = new FileInputStream(RES_NAME); prop.load(inputStream); inputStream.close(); System.out.println("init: " + lastModify); } } catch (Exception e) { e.printStackTrace(); } } /** * 返回单例对象引用 * @return */ public static ResManager getInstance() { return instance; } /** * 返回键值 * @param key * @return * @throws Exception */ public String getValue(String key) throws Exception { File file = new File(RES_NAME); if (lastModify < file.lastModified()) { // 资源文件被修改,重新载入文件内容 prop.clear(); lastModify = file.lastModified(); InputStream inputStream = new FileInputStream("res_en_US.properties"); prop.load(inputStream); inputStream.close(); } return prop.getProperty(key); } /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub ResManager manager = ResManager.getInstance(); for (int i = 0; i < 20; i++) { System.out.println(manager.getValue("total")); // 每次休眠 一定时间,可以修改资源文件测试打印内容是否变化 Thread.sleep(1000); } } }