Process process1 = Runtime.getRuntime().exec("javac hello.java");
Process process2 = Runtime.getRuntime().exec("java hello");
......
//现在程序要求键盘输入(因为程序中包含Scanner in = new Scanner(System.in))
//我的输入都包含在一个test.txt(不是一组测试数据,是很多组,一组可以执行一编程序);
//我给process2加上了它的输入流对象out//现在就是我要问的问题
long start=System.currentTimeMillis();//开始计时
byte[] b = test.getBytes();
out.write(b);//输入测试数据
out.close();
long end=System.currentTimeMillis();  //结束计时
if((end-start)>1000&&time!=0){//这里得到的是多组测试数据用去的时间,我想问怎么能得到一组数据的测试时间 ,或者告诉我一个更好的解决方法,有很多组测试数据,不要告诉我一组写成一个文件,会死人的,也不能算average
return "Time Limited";
}

解决方案 »

  1.   

    Using 'for' statement to read test.txt and calculate the time costing.for (each row data in .txt file){
      start timing;
      output data;
      end timing;  get the time costing;
    }
      

  2.   

    也许是我表达的问题~!
    说得通俗点就是你用一个java程序执行另一个java程序
    想知道另一个java程序的执行时间(另一个java是有数据输入的,输入的不是一组,但要得到是一组的测试时间,因为有一组数据就超时了就不用再测下去了)
      

  3.   

    分步来呗1. 先读出你的N组数据
    2. 对于N组数据的任一个调用一个Test
    3. 看你要求了,是有一个超时就返回或者是全执行完了看超时的个数...