Why does 'File.exists' return true, even though 'Files.exists' in the NIO 'Files' class returns false

前端 未结 2 1194
野趣味
野趣味 2020-12-09 17:49

I am trying to determine if a file exists in a network folder:

// File name is "\\\\QWERTY\\folder\\dir\\A123456.TXT"
Path path = Paths.get("\\         


        
2条回答
  •  借酒劲吻你
    2020-12-09 18:16

    i had a same problem, but your hack doesn't helped me. When file was actually exist all methods returned me false:

    Files.exists(path) = false, 
    path.toFile().exists() = false, 
    Files.notExists(path) = true, 
    Files.exists(path) || path.toFile().exists() = false
    

    But if at this moment in the explorer a network directory with this file was opened, then its existence was correctly handled

    I solved this problem by creation of a new file in directory (then delete it):

    Files.createFile(Paths.get(path.getParent().toString(), "test"));
    

    After that command, apparently, Windows update information about folder

提交回复
热议问题