/*TestProperties*/import java.util.Properties;
import java.util.Enumeration;public class TestProperties
{
public static void main(String[]args)
{
Properties props=System.getProperties();
Enumeration prop_names=props.propertyNames();
while(prop_names.hasMoreElements())
{
String prop_name=(String)prop_names.nextElement();
String property=props.getProperty(prop_name);
System.out.println("属性:"+prop_name+"'是"+property+"'");
}
}
}
{
Properties prop = null;
try
{
InputStream in = this.getClass().getClassLoader()
.getResourceAsStream("properties/dbconfig.properties");
prop = new Properties(); prop.load(in);
driver = prop.getProperty("driver");
dbURL = prop.getProperty("url");
user = prop.getProperty("user");
password = prop.getProperty("password");
in.close();
} catch (Exception e)
{
System.out.println("No dbconfig.properties defined error");
System.exit(-1);
}
}
读配置文件很方便