try {
BufferedReader br = new BufferedReader(new FileReader(user + ".txt"));
String time = t.toString();
while ((line = br.readLine()) != null) {
String [] check = line.split(";");
date.add(check[0]);
timeIn.add(check[1]);
timeOut.add(check[2]);
}
br.close();
BufferedWriter bw = new BufferedWriter(new FileWriter(user + ".txt"));
if (timeOut.contains("not_out")){
indx = timeOut.indexOf("not_out");
timeOut.set(indx, time);
}
for (int i = 0; i < date.size(); i++) {
d =getDate(i);
ti = ti(i);
to = to(i);
bw.write(d + ";" + ti + ";" + to);
bw.newLine();
}
bw.close();
} catch (Exception e) {
System.out.println("Time out error");
e.printStackTrace();
}
return true;
文本文件的内容是:覆盖文件中的Java
eg. 11/22/13;8:00;8:30
11/23/13;8:00;not_out
然后我将取代not_out
到当前的时间,因为我正在做的时间在和超时程序。 但总是输出是这样的:
11/22/13;8:00;8:30
11/22/13;8:00;8:30
11/23/13;8:00;8:40
它总是复制我的第一个记录。
是你在阅读后正确关闭文件?这似乎是封闭无处... – Learner
这是一个非常不完整的问题,你留下太多洞让我们能够提供帮助。 'ti(i)'做什么? “(我)”做了什么?他们持有什么?你有没有调试过这些家伙?你为什么不使用你已经填充的timeIn和timeOut集合?至少你应该加入一些println语句来查看你的问题在哪里。 –
那么ti(i)是一种获取数组内部元素的方法timeIn中的(i)就像ti方法,但它获取数组列表中的元素timeOut。 – user3194331