
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;

public class PropertiesUnit {
 private String filename;
 private Properties p;
 private FileInputStream in;
 private FileOutputStream out;
 public PropertiesUnit(String filename) {
  this.filename = filename;
  File file = new File(filename);
  try {
   in = new FileInputStream(file);
   p = new Properties();
   p.load(in);
   in.close();
  } catch (FileNotFoundException e) {
   System.err.println("配置文件找不到！");
   e.printStackTrace();
  } catch (IOException e) {
   System.err.println("配置文件错误！");
   e.printStackTrace();
  }
 }
 public String getValue(String itemName) {
  return p.getProperty(itemName);
 }
 public static void main(String args[]){
  String file="./classes/db.properties";
  PropertiesUnit pu=new PropertiesUnit(file);
  System.out.println(pu.getValue("database.user"));
  System.out.println(pu.getValue("database.password"));
 }

}
