简体   繁体   English

Windows 2008上的Java日志文件解析器无法使用File.lastModified

[英]Java log file parser on Windows 2008 is not able to use File.lastModified

We are using a simple log file parser written in Java. 我们正在使用用Java编写的简单日志文件解析器。 Log files are written using log4j.properties . 日志文件使用log4j.properties写入。 The parser relies on File.lastModified() to pick the list of files in directory to check if there are any errors in the file. 解析器依靠File.lastModified()来选择目录中的文件列表,以检查文件中是否存在任何错误。

This was working file until we moved to Windows 2008. After googling, I found file-date-modified-property-are-not-updating-while-modifying-a-file-without-closing-it that explained the behavior. 在我们移至Windows 2008之前,这个文件一直在工作。在谷歌搜索之后,我发现文件日期修改后的属性没有更新,而没有关闭文件就可以解释其行为。

So far I am not able to find any solution to this problem. 到目前为止,我无法找到解决该问题的任何方法。 My alternate option is to store the file size each time my poller check the file and compare the current file size with the previous stored value. 我的替代选择是每次轮询器检查文件时存储文件大小,并将当前文件大小与先前存储的值进行比较。

Can anyone suggest a simpler idea? 谁能提出一个更简单的想法?

Only putting it here to inform others if they face the same problem. 仅将其放在此处以告知其他人是否遇到相同的问题。 In my case it turned out a code issue where handle to the file was not closed properly. 就我而言,这是一个代码问题,该文件的句柄未正确关闭。 I used Process Explorer to see any unwanted open handles to the file. 我使用Process Explorer来查看该文件的所有不需要的打开句柄。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM