Using Standard Open Options - Java File Path IO

Java examples for File Path IO:File Operation

Introduction

OpenOption configures how to open or create a file.

OpenOption is an interface from the java.nio.file package and it has two implementations:

  • LinkOption class
  • StandardOpenOption class, which defines the following enums:
Value Meaning
READOpens file for read access
WRITE Opens file for write access
CREATE Creates a new file if it does not exist
CREATE_NEW Creates a new file, failing with an exception if the file already exists
APPPEND Appends data to the end of the file (used with WRITE and CREATE)
DELETE_ON_CLOSE Deletes the file when the stream is closed (used for deleting temporary files)
TRUNCATE_EXISTING Truncates the file to 0 bytes (used with the WRITE option)
SPARSE Causes the newly created file to be sparse
SYNC Keeps the file content and metadata synchronized with the underlying storage device
DSYNC Keeps the file content synchronized with the underlying storage device

Related Tutorials