Java核心代码例程之:PropertiesDemo.java
2008-01-05 08:38:28 来源:WEB开发网核心提示:import java.util.*;import java.io.*;/** * Demonstrates how to sort strings. ***/public class PRopertiesDemo{public static void main(String args[]) throws Except
import java.util.*;
import java.io.*;
/**
* Demonstrates how to sort strings.
***/
public class PRopertiesDemo
{
public static void main(String args[]) throws Exception
{
Properties props = new Properties();
props.put("db.user", "jack");
props.put("db.passWord", "opendoor");
// getProperty will return the value if found, otherwise null
System.out.println(props.getProperty("db.user"));
// getProperty will return the value if found, otherwise "none"
System.out.println(props.getProperty("db.password", "none"));
/*
// You can also load properties from a file
FileInputStream fis = new FileInputStream("my.properties");
props.load(fis);
fis.close();
**/
}
}
[]
更多精彩
赞助商链接