import java.io.InputStream; import java.util.Properties; public class FileProperties extends Properties{ public FileProperties(){} public FileProperties(String s) { try { InputStream inputStream = getClass().getResourceAsStream(s); load(inputStream); inputStream.close(); }catch (Exception e) { System.err.println("Exception in FileProperties(String): " + e.toString() + " for filename=" + s); } } public FileProperties(Properties properties) { super(properties); } public static String getMyProperty(String name){ FileProperties fp = new FileProperties("/cms.properties"); if ( fp != null ) { return fp.getProperty(name); } else { return null; } } }
屬性配置文件cms.properties格式爲:java
#Socket_TIM_Z = 0 47 17 * * ? Socket_TIM_J = 0 0 4 * * ? Socket_TIM_ZZH = 2 * * ? * *