每天早上使用Windows调度程序调用java程序

时间:2015-07-23 04:51:35

标签: java

我有一个java代码,需要每天早上由windows调用。但我不知道如何使用Windows调度程序调用java代码。 以下是我正在使用的代码段。

public class SchedulerMain {

public static void main(String[] args) {
    Timer timer = new Timer();
    TimerTask tt = new TimerTask() {
        private String Filepath = "C:\\Users\\IBM_ADMIN\\Desktop\\OUTPUTZIP\\TESTCASES_01997.xls";

        @Override
        public void run() {
            Calendar cal = Calendar.getInstance(); //

            int hour = cal.get(Calendar.HOUR_OF_DAY);//get the hour number of the day, from 0 to 23
            int min = cal.get(Calendar.MINUTE);


            if (hour == 18 && min == 14) {
                System.out.println("doing the scheduled task");

                Desktop dt = Desktop.getDesktop();
                try {
                    dt.open(new File(this.Filepath));
                } catch (IOException ex) {
                    Logger.getLogger(SchedulerMain.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    };
    timer.schedule(tt, 0, 1000 * 60);// delay the task 60 second, and then run task every five seconds
}
}

1 个答案:

答案 0 :(得分:0)

你能做什么呢 1)创建bat文件b.bat

b.bat

javac SchedulerMain.java
java SchedulerMain

保存此bat文件并在日程安排程序中使用此bat文件 希望它会有所帮助:)