ㅤㅤㅤ

PropertiesTest 읽는법 예제 입니다 본문

プログラミング/JAVA

PropertiesTest 읽는법 예제 입니다

ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ 2017. 7. 21. 11:17

package com.google.javacodetest;


import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStream;

import java.nio.file.Files;

import java.nio.file.Paths;

import java.util.Properties;


public class PropertiesTest {


public static void main(String[] args) {

// TODO Auto-generated method stub

try {


// 프로퍼티 파일 위치

String propFile = "C:\\Users\\kico\\Documents\\workspace-sts-3.8.4.RELEASE\\JavaCodeTest\\propertiesall\\test.properties";


// 프로퍼티 객체 생성

Properties props = new Properties();


// 프로퍼티 파일 스트림에 담기

FileInputStream fis = new FileInputStream(propFile);


// 프로퍼티 파일 로딩

props.load(new java.io.BufferedInputStream(fis));


// 항목 읽기

String msg = props.getProperty("MSG");

String msg1 = props.getProperty("SELECT1");


// 콘솔 출력

System.out.println(msg);

System.out.println(msg1);


} catch (Exception e) {

e.printStackTrace();

}


try (InputStream propFileInpStream = Files.newInputStream(Paths.get(

"C:\\Users\\kico\\Documents\\workspace-sts-3.8.4.RELEASE\\JavaCodeTest\\propertiesall\\test.properties"))) {

// do something with the input stream


Properties props = new Properties();

props.load(propFileInpStream);

String msg = props.getProperty("MSG");

String msg1 = props.getProperty("SELECT1");


// 콘솔 출력

System.out.println(msg);

System.out.println(msg1);



} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}


}




MSG=Prop OK!

SELECT1=SELECT account_balance FROM public.\"CUSTOMER_BANK_ACCOUNT\" WHERE bank_account_number=?;

Comments