Java中的File.delete是否执行文件锁定? [英] Does File.delete in java perform file locking?
本文介绍了Java中的File.delete是否执行文件锁定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 在删除文件之前,它是否已锁定文件?
- 需要吗?
- 如果它不执行文件锁定,如何确保它在多个进程之间安全?
推荐答案
也许这是链接 会更好地解释.据我了解,删除是一个原子操作,因此它不需要锁定文件. 但是,在进一步查看时,我发现了此链接 该图显示了删除操作与操作系统有关的性质.在Windows上,删除该文件时必然需要该文件没有锁,而在Linux上,您可以在另一个进程正在使用该文件的情况下删除该文件.
Maybe this link will explain better. As far as I understand, deletion is an atomic operation so it does not need to lock the file. However, upon looking further, I found this link which shows the OS dependent nature of the delete operation. On Windows, it will necessarily need the file to be without a lock to delete it while on Linux you can delete a file while another process is using it.
这篇关于Java中的File.delete是否执行文件锁定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文