这是我刚学java的test.txt文件。我想从此文件中搜索最新或最长的日期和时间。我的项目因此被困在这里,请帮助我。
Event Date and Time="2013/06/24 16:53:45"
Event Date and Time="2013/06/24 16:53:46"
Event Date and Time="2013/06/24 16:53:41"
Event Date and Time="2013/06/24 16:53:33"
Event Date and Time="2013/06/24 16:53:25"
这是我在while循环中所做的代码,我无法理解,请帮助我
try {
FileInputStream fstream1 = new FileInputStream(file);
DataInputStream in1= new DataInputStream(fstream1);
BufferedReader bf = new BufferedReader(new InputStreamReader(in1));
String line;
line=bf.readLine();
boolean myheader = checkHeader(line.trim());
if(!myheader)
{
while (( line = bf.readLine()) != null)
{
}
}
catch(Exception)
{
}
private static boolean checkHeader(String headerString) {
boolean result = true;
String[] headerElements = headerString.split(":");
List<String> list = new ArrayList<String>();
for(int i = 0; i < headerElements.length; i++){
if(i != headerElements.length - 1)
list.add(headerElements[i] + ":");
else
list.add(headerElements[i]);
}
for(String listElements : list){
if(!HEADER.contains(listElements)){
result = false;
break;
}
}
return result;
}