我之前问过这个问题但是我得不到我期望的答案。因此我打开了这个新问题。
我的尝试:
String fileName = "placements.csv";
try {
// Assume default encoding.
FileWriter fileWriter = new FileWriter(fileName);
// Always wrap FileWriter in BufferedWriter.
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
// First row, write the head of the csv file.
bufferedWriter.write(FILE_HEADER);
bufferedWriter.newLine();
// Increase the begin date 1 seconds until test end date.
int seconds = 0;
Calendar cal = Calendar.getInstance();
cal.setTime(beginDate);
for (int j = 0; j < convertedDifference; j++) {
for (Job currentJob : NEHCalculator.sequenceOrderListofJobs()) {
int times = (int) ((convertedDifference / currentJob.getInterval()) * testDevices());
for (int i = 0; i < currentJob.getNeededTestTime() * times; i++) {
cal.add(Calendar.SECOND, 1);
beginDate.getTime();
// write the test date
bufferedWriter.write(String.valueOf(cal.getTime()));
bufferedWriter.write(";");
bufferedWriter.write(String.valueOf(seconds));
bufferedWriter.write(";");
bufferedWriter.write(currentJob.getJobname());
bufferedWriter.write(";");
bufferedWriter.newLine();
}// end of currentjob loop
seconds++;
}// end first for loop
}
bufferedWriter.close();// Always close files.
} catch (IOException ex) {
System.out.println("Error writing to file '" + fileName);
}
}
首先进行循环for (int j = 0; j < convertedDifference; j++)
:我将程序限制在测试结束日期之前。如果我进入1小时的测试时间,我希望看到0到3599秒。
循环for (Job currentJob : NEHCalculator.sequenceOrderListofJobs())
的第二个:我想测试列表中的每个设备。
对于第三个for循环for (int i = 0; i < currentJob.getNeededTestTime() * times; i++)
:我希望测试第一个作业currentJob.getNeededTestTime() * times times
。
例如,我有1小时的测试时间和第一个工作的间隔是15分钟,它测试2个设备并测试所需的时间2秒。所以输出必须是:
Mon Feb 22 12:59:59 CET 2016;0;WAF5-H;
Mon Feb 22 13:00:00 CET 2016;1;WAF5-H;
Mon Feb 22 13:00:01 CET 2016;2;WAF5-H;
Mon Feb 22 13:00:02 CET 2016;3;WAF5-H;
Mon Feb 22 13:00:03 CET 2016;4;WAF5-H;
Mon Feb 22 13:00:04 CET 2016;5;WAF5-H;
Mon Feb 22 13:00:05 CET 2016;6;WAF5-H;
Mon Feb 22 13:00:06 CET 2016;7;WAF5-H;
Mon Feb 22 13:00:07 CET 2016;8;WAF5-H;
Mon Feb 22 13:00:08 CET 2016;9;WAF5-H;
Mon Feb 22 13:00:09 CET 2016;10;WAF5-H;
Mon Feb 22 13:00:10 CET 2016;11;WAF5-H;
Mon Feb 22 13:00:11 CET 2016;12;WAF5-H;
Mon Feb 22 13:00:12 CET 2016;13;WAF5-H;
Mon Feb 22 13:00:13 CET 2016;14;WAF5-H;
Mon Feb 22 13:00:14 CET 2016;15;WAF5-H; then it will continue with second job until end of the job list.
然而,我的代码输出是:
Mon Feb 22 12:59:59 CET 2016;0;WAF5-H;
Mon Feb 22 13:00:00 CET 2016;0;WAF5-H;
Mon Feb 22 13:00:01 CET 2016;0;WAF5-H;
Mon Feb 22 13:00:02 CET 2016;0;WAF5-H;
Mon Feb 22 13:00:03 CET 2016;0;WAF5-H;
Mon Feb 22 13:00:04 CET 2016;2;WAF5-H;
Mon Feb 22 13:00:05 CET 2016;2;WAF5-H;
Mon Feb 22 13:00:06 CET 2016;2;WAF5-H;
Mon Feb 22 13:00:07 CET 2016;2;WAF5-H;
Mon Feb 22 13:00:08 CET 2016;2;WAF5-H; until Mon Feb 22 17:55:08 CET 2016;7082;WAF5-H;
这是完全错误的,我花了很多时间,但我没有完成这项任务。有人可以帮助我。
致以最诚挚的问候,
答案 0 :(得分:1)
如何更改此代码
bufferedWriter.write(String.valueOf(seconds));
这个:
bufferedWriter.write(String.valueOf(cal.get(Calendar.SECOND)));
我认为它可能有效