public enum FileLocks extends Enum<FileLocks>
Per javadoc of FileLock, "File locks are held on behalf of the entire
Java virtual machine. They are not suitable for controlling access to a file
by multiple threads within the same virtual machine."
Hence the need for this utility class.
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
isFileLocked(File file)
Returns true if the specified file is currently locked; false otherwise.
|
static boolean |
lock(File file)
Acquires an exclusive lock on the specified file, creating the file as
necessary.
|
static boolean |
unlock(File file)
Unlocks a file previously locked via
lock(File). |
static FileLocks |
valueOf(String name)
返回带有指定名称的该类型的枚举常量。
|
static FileLocks[] |
values()
按照声明该枚举类型的常量的顺序, 返回
包含这些常量的数组。
|
public static FileLocks[] values()
for (FileLocks c : FileLocks.values()) System.out.println(c);
public static FileLocks valueOf(String name)
name - 要返回的枚举常量的名称。IllegalArgumentException - 如果该枚举类型没有带有指定名称的常量NullPointerException - 如果参数为空值public static boolean lock(File file)
unlock(File) method to prevent release leakage.FileLockException - if we failed to lock the filepublic static boolean isFileLocked(File file)
public static boolean unlock(File file)
lock(File).Copyright © 2022. All rights reserved.