这个和简单 但要是你的Java程序一直运行着才行 那样还不如用Windows的task任务就好了 还是给给代码 不太喜欢给答案 给启发性的test 用到了Java中 启动程序的方法 Process pro = Runtime.getRuntime().exec("notepad src\\Test1.java"); public void testSR(){ long begin = System.currentTimeMillis();
Properties p = System.getProperties(); Enumeration e = p.propertyNames(); while(e.hasMoreElements()){ String str = (String) e.nextElement(); System.out.println(str); }
try { Process pro = Runtime.getRuntime().exec("notepad src\\Test1.java"); Thread.sleep(10000); pro.destroy(); } catch (IOException e1) { e1.printStackTrace(); }catch (InterruptedException e1) { e1.printStackTrace(); } long end = System.currentTimeMillis(); System.out.println("Used time :" + (end - begin)); }
那样还不如用Windows的task任务就好了
还是给给代码 不太喜欢给答案 给启发性的test
用到了Java中 启动程序的方法
Process pro = Runtime.getRuntime().exec("notepad src\\Test1.java"); public void testSR(){
long begin = System.currentTimeMillis();
Properties p = System.getProperties();
Enumeration e = p.propertyNames();
while(e.hasMoreElements()){
String str = (String) e.nextElement();
System.out.println(str);
}
try {
Process pro = Runtime.getRuntime().exec("notepad src\\Test1.java");
Thread.sleep(10000);
pro.destroy();
} catch (IOException e1) {
e1.printStackTrace();
}catch (InterruptedException e1) {
e1.printStackTrace();
}
long end = System.currentTimeMillis();
System.out.println("Used time :" + (end - begin));
}
方向的资料了
时间 可以取机器时间 来判断 这个 看看 Date等时间类就好了
import java.io.File;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
public class TimeExecute
{ /**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
Timer timer=new Timer();
TimerTask task=new TimerTask()
{
public void run()
{
Desktop desktop= Desktop.getDesktop();
try
{
desktop.open(new File("D:\\Program Files\\Tencent\\QQ\\QQ.exe"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
timer.schedule(task,100);//改成毫秒数 }}
可以调用cmd命令,也可以调用自己写的批处理
起个线程,判断当前时间和你要执行程序的时间比较
当前时间大于等于执行程序时间调用
Runtime.getRuntime().exec("")