CKTIS / Java
nio.file.StandardOpenOption: practical reference
nio.file.StandardOpenOption: practical reference: StandardOpenOption enumerates file-open policies such as CREATE, TRUNCATE_EXISTING, APPEND, and SYNC.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
java.nio.file.StandardOpenOptionStandardOpenOption enumerates file-open policies such as CREATE, TRUNCATE_EXISTING, APPEND, and SYNC.
Choose StandardOpenOption combinations explicitly so creation, truncation, append, durability, and deletion behavior match the write protocol.
CREATE does not fail when the file exists, while CREATE_NEW does. TRUNCATE_EXISTING matters only with write access; APPEND writes at the end but atomicity under concurrent writers is provider-specific.
SYNC includes content and metadata durability, whereas DSYNC covers content updates. DELETE_ON_CLOSE and SPARSE are provider-dependent best-effort or optional behaviors.
The example exercises the documented element in a small deterministic program and compares exact standard output.
Examples
public class Main {
public static void main(String[] args) throws Exception {
java.nio.file.StandardOpenOption option = java.nio.file.StandardOpenOption.APPEND;
System.out.println(option.name());
}
}
Result
APPEND
The example exercises the documented element in a small deterministic program and compares exact standard output.