java中Properties类的使用

来源:互联网 发布:翻墙登录软件 编辑:程序博客网 时间:2024/05/16 15:50
package com.adrop.util;
 
import java.io.*;
import java.util.Properties;
import javax.servlet.http.*;
import javax.servlet.*;
import javax.servlet.jsp.*;
 
public class PropertiesUtil {
 private String fileName;
 private Properties p;
 private FileInputStream in;
 private FileOutputStream out;
 /**
   * 根据传进的文件名载入文件
   * @param fileName String
   */
 public PropertiesUtil(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("配置文件config.properties找不到!!");
      e.printStackTrace();
    }
    catch (Exception e) {
      System.err.println("读取配置文件config.properties错误!!");
      e.printStackTrace();
    }
 }
 
 /**
   * 配置文件一律为config.propertities,并且统一放在web应用的根目录下。
   * @return String
   */
 public static String getConfigFile(HttpServlet hs) {
 
    return getConfigFile(hs,"config.properties");
 }
 /**
   *