⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configmanager.java

📁 java编写的监控一个文件夹里面有没有新的excel文件放入
💻 JAVA
字号:
/**
 * 
 */
package com.justin.config;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import java.io.*;
import com.justin.log.*;
/**
 * @author Justin
 *
 * 单例模式实现,此类用来读取并存放程序的配置信息
 */
public class ConfigManager {
	
	private static Properties prop;
	private static ConfigManager config = null;
	
	public synchronized static ConfigManager getInstance(){
		if (config == null){
			config = new ConfigManager();
		}
		return config;
	}
	
	private ConfigManager(){
		try {
			
			prop = new Properties();
			
			//设置默认属性
			prop.setProperty("AppRoot", (String)System.getProperty("user.dir"));
			prop.setProperty("DetectInterval", "3000");
			prop.setProperty("DetectDir","C:\\Data");
			
			//加载用户定制的配制文件
			prop.load(new FileInputStream((String)System.getProperty("user.dir")+"\\config.properties"));
			
			//输出默认属性及配置文件的内容
			prop.list(System.out);
		
		} catch (IOException ex) {
			System.out.println("No Config File");
		}	
	}
	
	//在用户界面显示所有的属性及值
	public synchronized void list(LogServer log){
		log.showMessage("-- listing properties --");
		Hashtable<String, String> h = new Hashtable<String, String>();
		for (Enumeration e = prop.keys() ; e.hasMoreElements() ;) {
		    String key = (String)e.nextElement();
		    h.put(key, (String)prop.get(key));
		}
		for (Enumeration e = h.keys() ; e.hasMoreElements() ;) {
		    String key = (String)e.nextElement();
		    String val = (String)h.get(key);
		    if (val.length() > 40) {
	                val = val.substring(0, 37) + "...";
		    }
		    log.showMessage(key + "=" + val);
		}
	}
	
	//在输出流中显示所有属性及值
	public synchronized void list(PrintStream out){
		prop.list(out);
	}
	
	//返回监测间隔属性值
	public synchronized int getDetectInterval(){
		int interval = 2000;  
		try{
			interval = Integer.parseInt(prop.getProperty("DetectInterval"));		
		}catch(NumberFormatException ex){
			System.out.println("DetectInterval数据类型错误(整型)");
		}				
		return interval;
		
		
	}	
	
	//返回监测目录文件夹属性值
	public synchronized String getDetectDir(){
		return prop.getProperty("DetectDir");
	}
	
	//返回应用程序根路径属性值
	public synchronized String getAppRoot(){
		return prop.getProperty("AppRoot");
	}
	
	//返回监测文件类型属性值
	public synchronized String getDetectExt(){
		return prop.getProperty("DetectExt");
	}
	
	//返回是否处于Debug状态
	public synchronized boolean isDebug(){
		boolean isDebug = false;
		try{			
			isDebug = Boolean.valueOf(prop.getProperty("Debug")).booleanValue();		
		}catch(NumberFormatException ex){
			System.out.println("Debug数据类型错误(false/true)");
		}
		return isDebug;
	}
	
	public synchronized String getBackupDir(){
		return prop.getProperty("BackupDir");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -