public String getlog() throws IOException, ParseException{
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long now_time = System.currentTimeMillis();
long before_one_hour_time = now_time - 3600000;
FileInputStream fis = new FileInputStream("E:/log/data.log.2010-05-26");
Iterator<String> itr = IOUtils.lineIterator(fis, "utf-8");
while (itr.hasNext())
{
String line = itr.next();
String lineTime = line.substring(0, 19);
String str=line.substring(20);
long time = format.parse(lineTime).getTime();
if (time >= before_one_hour_time && time <= now_time)
{
String str1=line.substring(20);
return str1;
}
else
{
return null;
}
}
return null;
}
读log文件及与时间对比
最新推荐文章于 2015-04-06 17:29:00 发布