package test; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Properties; public class Configuration { private String address; private String port; private String username; private String password; public final static String CONFIG_FILE = "conf.properties"; public Configuration() { // TODO Auto-generated constructor stub } public Configuration(String address, String port, String username, String password) { //super(); this.address = address; this.port = port; this.username = username; this.password = password; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getPort() { return port; } public void setPort(String port) { this.port = port; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public static Configuration getInstance() { File file = new File (Configuration.CONFIG_FILE); Properties prop = new Properties(); try { prop.load(new FileReader(file)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String a = prop.getProperty("address"); String p = prop.getProperty("port"); String u = prop.getProperty("username"); String pwd = prop.getProperty("password"); return new Configuration(a, p, u, pwd); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Configuration conf = Configuration.getInstance(); System.out.println(conf.getAddress()); System.out.println(conf.getPort()); System.out.println(conf.getUsername()); System.out.println(conf.getPassword()); } } 相对应的Propertise文件内容 address=127.0.0.1 port=1521 username=test password=test