import java.io.File;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.Timer;
import org.apache.log4j.Logger;
import com.huawei.ngbss.common.XMLParserHelperDom4j;
public class FileManager
{
// 注册的监听文件列表
private static HashMap<String, FileListener> FMap = new HashMap<String, FileListener>();
// 配置文件路径(从命令行传入)
private String configFile = null;
// 默认配置文件(从JAR包中加载)
private String defaultConfigFile = "FileListener.properties";
//本地日志记录
private static Logger logger = Logger.getLogger(FileManager.class);
public static void main(String[] args)
{
FileManager fm = new FileManager();
if (args.length > 0)
{
fm.configFile = args[1];
}
if (FMap.size() == 0)
{
fm.regFileListener();
logger.info("Execute Command sucess.");
System.out.println("loading file.......");
}
else
{
logger.info("The program is running.can not run again.");
}
}
/**
* 注册需要监听的文件(从配置文件读取配置信息)
*/
public void regFileListener()
{
Properties prop = loadProperties();
//得到要监听的文件数
String num = prop.getProperty("ListenerFileNum");
System.out.println(num);
//得到监听文件时的时间限定
String Interval = prop.getProperty("Interval");
if (("".equals(num)) || (null == num) || ("".equals(Interval))
|| (null == Interval))
{
logger.error("Configuration error,please check it! Inteval:"
+ Interval + ",ListenerFileNum:" + num);
}
else
{
int number = Integer.parseInt(num);
int t = Integer.parseInt(Interval);
for (int i = 0; i < number; i++)
{
//得到要监听文件的路径
String filePath = prop.getProperty("ListenerFile" + (i + 1));
if (filePath != null)
{
//如果得到的路径指定的是文件夹,将加载文件夹下所有的文件.
if (filePath.endsWith(File.separator))
{
regBatchFile(filePath, t);
}
else
{
regSingleFile(filePath, t);
}
}
else
{
logger.error("Configuration item[LitenerFileNum]" + (i + 1)
+ "[does not exist.ignore]...");
}
}
}
}
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.Timer;
import org.apache.log4j.Logger;
import com.huawei.ngbss.common.XMLParserHelperDom4j;
public class FileManager
{
// 注册的监听文件列表
private static HashMap<String, FileListener> FMap = new HashMap<String, FileListener>();
// 配置文件路径(从命令行传入)
private String configFile = null;
// 默认配置文件(从JAR包中加载)
private String defaultConfigFile = "FileListener.properties";
//本地日志记录
private static Logger logger = Logger.getLogger(FileManager.class);
public static void main(String[] args)
{
FileManager fm = new FileManager();
if (args.length > 0)
{
fm.configFile = args[1];
}
if (FMap.size() == 0)
{
fm.regFileListener();
logger.info("Execute Command sucess.");
System.out.println("loading file.......");
}
else
{
logger.info("The program is running.can not run again.");
}
}
/**
* 注册需要监听的文件(从配置文件读取配置信息)
*/
public void regFileListener()
{
Properties prop = loadProperties();
//得到要监听的文件数
String num = prop.getProperty("ListenerFileNum");
System.out.println(num);
//得到监听文件时的时间限定
String Interval = prop.getProperty("Interval");
if (("".equals(num)) || (null == num) || ("".equals(Interval))
|| (null == Interval))
{
logger.error("Configuration error,please check it! Inteval:"
+ Interval + ",ListenerFileNum:" + num);
}
else
{
int number = Integer.parseInt(num);
int t = Integer.parseInt(Interval);
for (int i = 0; i < number; i++)
{
//得到要监听文件的路径
String filePath = prop.getProperty("ListenerFile" + (i + 1));
if (filePath != null)
{
//如果得到的路径指定的是文件夹,将加载文件夹下所有的文件.
if (filePath.endsWith(File.separator))
{
regBatchFile(filePath, t);
}
else
{
regSingleFile(filePath, t);
}
}
else
{
logger.error("Configuration item[LitenerFileNum]" + (i + 1)
+ "[does not exist.ignore]...");
}
}
}
}