개발/Java
properties 파일 읽기(read)
용술이
2021. 5. 30. 10:32
batch에 대한 요청이 들어와서, 소스 안에 url 정보 등을 강제로 박아서 배포해 주었다. url 정보등은 static 정보라 생각되어
" 뭐 나중에 필요하면 수정 요청 하겠지"
하며, jar로 만들어서 배포 해줬는데, 수정이 빈번 한가 보다.
그래서 properties 파일에 필요한 옵션 정보를 사용 하고, 필요할때 정해진 규칙에 따라 수정 하면, 바로 반영 될 수 있도록 수정 해 주었다.
1. properties 파일 읽기
1
2
3
4
5
6
7
8
9
10
11
12
13
|
@Test
public void getProperties() {
Properties properties = new Properties();
try {
properties.load(new FileInputStream("D:\\test\\src\\test\\java\\sample.properties"));
} catch (IOException e) {
e.printStackTrace();
}
String url = properties.getProperty("url");
System.out.println(url);
}
|
cs |
2. properties 파일 내용
#정보
sample_url=http://127.0.0.1:8080
3. 결과
반응형