比较常用的Properties配置文件的使用方法示例

import java.io.IOException;
import java.util.Properties;


/**
 * 配置的相关信息
 * @author 
 *
 */
public class IDSServerConfig{

 private static final String configFile = "SystemConfig.properties";//配置文件名称
 private static IDSServerConfig IDSAuth;
 protected static Properties ProFile = new Properties();
 
 private String idsServerAddress;
 private String idsAuthorizationService;
 private String idsAuthSystemCode;
 private String idsAuthInterval;
 private String redirectpath;
 private String forbidedUrlPattern;
 private String idsLoginUrl;
 private String idsLogoutUrl;
 private String idsDbDriver;
 private String idsDbUrl;
 private String idsDbUsername;
 private String idsDbPassword;
 
 private IDSServerConfig() {}
 
 public static void init() {
  try {
   ProFile.load(IDSServerConfig.class.getResourceAsStream("/" + configFile));
   IDSAuth = new IDSServerConfig();
   IDSAuth.setIdsServerAddress(ProFile.getProperty("idsServerAddress"));
   IDSAuth.setIdsAuthorizationService(ProFile.getProperty("idsAuthorizationService"));
   IDSAuth.setIdsAuthSystemCode(ProFile.getProperty("idsAuthSystemCode"));
   IDSAuth.setIdsAuthInterval(ProFile.getProperty("idsAuthInterval"));
   IDSAuth.setRedirectpath(ProFile.getProperty("redirectpath"));
   IDSAuth.setForbidedUrlPattern(ProFile.getProperty("forbidedUrlPattern"));
   IDSAuth.setIdsLoginUrl(ProFile.getProperty("idsLoginUrl"));
   IDSAuth.setIdsLogoutUrl(ProFile.getProperty("idsLogoutUrl"));
   IDSAuth.setIdsDbDriver(ProFile.getProperty("idsDbDriver"));
   IDSAuth.setIdsDbUrl(ProFile.getProperty("idsDbUrl"));
   IDSAuth.setIdsDbUsername(ProFile.getProperty("idsDbUsername"));
   IDSAuth.setIdsDbPassword(ProFile.getProperty("idsDbPassword"));
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
 
 
 public static IDSServerConfig getInstance() {
  return IDSAuth;
 }
 public String getIdsServerAddress() {
  return idsServerAddress;
 }
 public void setIdsServerAddress(String idsServerAddress) {
  this.idsServerAddress = idsServerAddress;
 }
 public String getIdsAuthorizationService() {
  return idsAuthorizationService;
 }
 public void setIdsAuthorizationService(String idsAuthorizationService) {
  this.idsAuthorizationService = idsAuthorizationService;
 }
 public String getIdsAuthSystemCode() {
  return idsAuthSystemCode;
 }
 public void setIdsAuthSystemCode(String idsAuthSystemCode) {
  this.idsAuthSystemCode = idsAuthSystemCode;
 }
 public String getIdsAuthInterval() {
  return idsAuthInterval;
 }
 public void setIdsAuthInterval(String idsAuthInterval) {
  this.idsAuthInterval = idsAuthInterval;
 }
 public String getRedirectpath() {
  return redirectpath;
 }
 public void setRedirectpath(String redirectpath) {
  this.redirectpath = redirectpath;
 }
 public String getForbidedUrlPattern() {
  return forbidedUrlPattern;
 }
 public void setForbidedUrlPattern(String forbidedUrlPattern) {
  this.forbidedUrlPattern = forbidedUrlPattern;
 }

 public String getIdsLoginUrl() {
  return idsLoginUrl;
 }

 public void setIdsLoginUrl(String idsLoginUrl) {
  this.idsLoginUrl = idsLoginUrl;
 }

 public String getIdsLogoutUrl() {
  return idsLogoutUrl;
 }

 public void setIdsLogoutUrl(String idsLogoutUrl) {
  this.idsLogoutUrl = idsLogoutUrl;
 }

 public String getIdsDbDriver() {
  return idsDbDriver;
 }

 public void setIdsDbDriver(String idsDbDriver) {
  this.idsDbDriver = idsDbDriver;
 }

 public String getIdsDbUrl() {
  return idsDbUrl;
 }

 public void setIdsDbUrl(String idsDbUrl) {
  this.idsDbUrl = idsDbUrl;
 }

 public String getIdsDbUsername() {
  return idsDbUsername;
 }

 public void setIdsDbUsername(String idsDbUsername) {
  this.idsDbUsername = idsDbUsername;
 }

 public String getIdsDbPassword() {
  return idsDbPassword;
 }

 public void setIdsDbPassword(String idsDbPassword) {
  this.idsDbPassword = idsDbPassword;
 }
 
}

你可能感兴趣的:(properties)