I never thought it would happen to me, but I ran into my first bug in Java:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5003595
I'm pretty much in the same exact situation as described in the bug (NFS on linux), and I'm seeing that File.exists()
is not returning the correct value (at least not right away).
So my question is, is there any alternative to this method of checking if a file exists? I'd prefer to keep it OS agnostic if possible.
EDIT: I have found a workaround. If you make a call to ls $filedir
, the NFS refreshes whatever cache/metadata that is giving Java trouble, and File.exists()
returns the correct value. Granted, this isn't totally ideal, since it hurts portability, but there are ways to deal with that problem.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…