enum 응용, Properties (속성) 사용 예제


########## PropertiesFactory.java #############

   
public class PropertiesFactory {

	public static Properties getProperties(String propertiesPath) {
		
		Properties prop = new Properties();
		
		try {
			prop.load(new FileReader(propertiesPath));
		} catch (FileNotFoundException e) {
			
			System.err.println("Message : " + e.getMessage());
			return null;
		} catch (IOException e) {
			
			System.err.println("Message : " + e.getMessage());
			return null;
		}
		
		return prop;
	}
}


########## PropertiesPath.java #############

   
public enum PropertiesPath {

	SVR_DEV("com/properties/svr.dev.properties"),
	SVR_REAL("com/properties/svr.real.properties"),

	ENV("com/properties/env.properties");
	
	private String path = "";
	
	private PropertiesPath(String path) {
		this.path = path;
	}
	
	public String build() {
		return this.path;
	}
}


############ com/properties/svr.dev.properties ###############

   
#dev server
item.url=http://localhost:7080/book/item
color.url=http://localhost:7080/book/color


############# 사용예  ################

   
Properties prop = PropertiesFactory.getProperties(PropertiesPath.SVR_DEV.build());
String item = prop.getProperty("item.url");	// http://localhost:7080/book/item
String color_url = prop.getProperty("color.url");	 // http://localhost:7080/book/color



'자바 일반' 카테고리의 다른 글

java 폴더 생성  (0) 2014.09.11
MATLAB 실행 오류  (0) 2014.09.04
json gson  (0) 2014.08.25
InputStream 을 String 으로 변환하기  (0) 2014.08.25
[Java]Collections.sort로 정렬하기(문자열, 숫자)  (0) 2014.07.28

+ Recent posts