简体   繁体   English

File.exists()对于Samba共享网络文件夹上的现有文件返回“ false”

[英]File.exists() return 'false' for existing file on Samba share network folder

I know for sure that the file exists on Samba share. 我确定该文件存在于Samba共享上。 But file.exists() return 'false' for it. 但是file.exists()返回'false' Another system puts this file in a Samba share folder and notifies our application that the file is uploaded. 另一个系统将此文件放在Samba共享文件夹中,并通知我们的应用程序该文件已上传。 Than we invoke file.exists() for check this and get 'false' 比我们调用file.exists()进行检查并得到'false'

Path sourceFile = ... 
sourceFile.toFile().exists() 
//return 'false' for existing file with path like \\share1\mc\logs.txt

Maybe the file has not yet been completely written or has not been completely closed, could that affect the result file.exists() ? 也许文件尚未完全写入或尚未完全关闭,这可能会影响结果file.exists()吗?

Well, at least the behaviour you're observing is covered by the documentation 好吧,至少您观察到的行为已包含在文档中

false if the file does not exist or its existence cannot be determined 如果文件不存在或无法确定其存在,则返回 false

(emphasis added). (强调)。

Might be related to this question here: Why does 'File.exists' return true, even though 'Files.exists' in the NIO 'Files' class returns false , though the answers seem a bit inconclusive to me. 在这里可能与此问题有关: 尽管NIO“ Files”类中的“ Files.exists”返回false为什么“ File.exists”返回true ,尽管答案对我来说似乎没有定论。

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

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