/** * 如果proertiesFile不存在,那么返回参数thing,如果存在,那么先thing.detach()一个新的事物,然后 在properties里的参数复制到新的事物上,并返回新的事物。 * * @param thing * @param propertiesFile * @return * @throws IOException */ public static Thing createPropertiesThing(Thing thing, String propertiesFile) throws IOException { if (propertiesFile != null && !"".equals(propertiesFile)) { File file = new File(propertiesFile); if (file.exists()) { Properties p = new Properties(); FileInputStream fin = new FileInputStream(file); try { p.load(fin); } finally { fin.close(); } // 新建一个thing,用于替换属性 Thing newThing = thing.detach(); for (Object key : p.keySet()) { newThing.getAttributes().put(key.toString(), p.get(key)); } return newThing; } return thing; } else { return thing; } }