Here is a example:
import java.util.*;
InputStream is = getClass().getResourceAsStream("/db.properties");
Properties dbProps = new Properties();
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");
try
{
log = new PrintWriter(new FileWriter(logFile, true), true);
}
catch(Exception e)
{
System.err.println("Can't open the log file: " + logFile);
log = new PrintWriter(System.err);
}
OK, this is a clip of the DBConnectionManager.java, OK you can refer to this package.
import java.util.*;
InputStream is = getClass().getResourceAsStream("/db.properties");
Properties dbProps = new Properties();
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");
try
{
log = new PrintWriter(new FileWriter(logFile, true), true);
}
catch(Exception e)
{
System.err.println("Can't open the log file: " + logFile);
log = new PrintWriter(System.err);
}
OK, this is a clip of the DBConnectionManager.java, OK you can refer to this package.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货