接下来我现在遇到一个设计的问题。 下面的程序代码是一个指定时间间隔执行调用FtpClient类来读取my.properties文件 流程如下: 1、Scheduler启动的代码 public class SimpleExample { public void run() throws Exception { SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sched = sf.getScheduler(); JobDetail job = new JobDetail("job1", "group1", HelloJob.class); Trigger trigger = TriggerUtils.makeSecondlyTrigger(5); trigger.setName("hehe"); sched.scheduleJob(job, trigger); sched.start(); } public static void main(String[] args) { SimpleExample example = new SimpleExample(); try { example.run(); } catch (Exception e) { e.printStackTrace(); } } }
2、HelloJob类 public class HelloJob implements Job { public HelloJob() { } public void execute(JobExecutionContext context) throws JobExecutionException { try { FtpClient.ReadProperties("my.properties"}); } catch (Exception e) { e.printStackTrace(); } }
} 3、FtpClient类 public class FtpClient { private static final int NO_OF_PROPERTIES_ITEMS = 4; public static void ReadProperties(String fileName) throws Exception { InputStream in; String strDummy = ""; StringTokenizer st;
in = new FileInputStream(fileName); BufferedReader r = new BufferedReader(new InputStreamReader(in, System .getProperty("file.encoding"))); java.util.Properties prop = new java.util.Properties(); for (int i = 0; i < NO_OF_PROPERTIES_ITEMS; i++) { strDummy = r.readLine(); st = new StringTokenizer(strDummy, "=");