リソースファイルにロードされたクラス

1036 ワード


public class ReadProperties {
	/*
	 *               ,   Properties  
	 *  (non-Javadoc)
	 * @see com.voole.interf.IProperties#getProperties()
	 * @return Properties  
	 */
	public static Properties getProperties() {
		return getProperties("/config.properties");
	}
	
	public static Properties getProperties(String path) {
		InputStream inStream = ReadProperties.class.getResourceAsStream(path);
		Properties prop = new Properties();
		try {
			if(inStream != null){
				prop.load(inStream);
				inStream.close();
			}
		} catch (IOException e) {
			System.out.println("              !"+e.getMessage());
		}
		return prop;
	}
	
	//  
	public static void main(String[] args) {
		Properties pr = ReadProperties.getProperties();
		System.out.println("mysql connection -- " + pr.getProperty("SQL_DRIVER"));
	}
}