/** * 每隔5秒就启动一次QQ */ public class Test { public static void main(String[] args){ Timer timer = new Timer(); timer.schedule(new MonitorInfraredTask(), 0, 5*1000); //每隔5秒启动QQ } } class MonitorInfraredTask extends TimerTask{ public void run() { //打开QQ try { Runtime.getRuntime().exec("C://Program Files//Tencent//QQ//QQ.exe"); } catch (Exception e) { System.out.println("启动QQ异常:"+e.getMessage()); } } } /** * 仅启动一次QQ */ public class Test { public static void main(String[] args){ Timer timer = new Timer(true); timer.schedule(new MonitorInfraredTask(), 0, 5*1000); //每隔5秒启动QQ } } class MonitorInfraredTask extends TimerTask{ public void run() { //打开QQ try { Runtime.getRuntime().exec("C://Program Files//Tencent//QQ//QQ.exe"); } catch (Exception e) { System.out.println("启动QQ异常:"+e.getMessage()); } } }