Properties example
import java.io.*;
import java.util.Properties;
/* 다음과 같이 db.properties 파일을 작성하여 이 소스와 동일한 곳에 저장한 후에
* 이 파일을 테스트한다.
drivers=oracle.jdbc.OracleDriver
logfile=log.txt
mypool.url=jdbc:oracle:thin:@localhost:1521:ORCL
mypool.user=scott
mypool.password=tiger
mypool.maxconn=3
*/
class PropertiesTest
{
public static void main(String[] args)
{
PropertiesTest test = new PropertiesTest();
}
public PropertiesTest() {
InputStream is = getClass().getResourceAsStream("db.properties");
Properties dbProps = new Properties();
PrintWriter log = null;
try {
dbProps.load(is);
}
catch (Exception e) {
System.err.println("Can't read the properties file. " +
"Make sure db.properties is in the CLASSPATH");
return;
}
String logFile = dbProps.getProperty("logfile", "DBConnectionManager.log");
String db_url = dbProps.getProperty("mypool.url");
System.out.println(db_url);
try {
log = new PrintWriter(new FileWriter(logFile, true), true);
}
catch (IOException e) {
System.err.println("Can't open the log file: " + logFile);
log = new PrintWriter(System.err);
}
}
}