exists file java,在Java中替代File.exists()

博主在Java中遇到NFS缓存导致的File.exists()返回不准确的问题。文章探讨了问题原因,并提供了通过`ls`命令刷新NFS缓存的临时解决办法。还介绍了NFS属性缓存可能带来的性能影响及如何考虑设计更通用的解决方案。
摘要由CSDN通过智能技术生成

I never thought it would happen to me, but I ran into my first bug in Java:

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.

Thanks,

-Ben

解决方案

The basic problem you have with NFS is that it caches attributes, files and directories information. This means the information can be out of date. You might be able to turn off caching, you will see a significant reduction in performance.

The important thing to remember is that NFS is not a messaging service and is not designed for timely delivery of data.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值