APPEND If the file is already open for write then append to the end.
TRUNCATE_EXISTING If file is already open for write then erase file and append to beginning.
APPEND
public static final StandardOpenOption APPEND
If the file is opened for WRITE access then bytes will be written to the end of the file rather than the beginning.
If the file is opened for write access by other programs, then it is file system specific if writing to the end of the file is atomic.
TRUNCATE_EXISTING
public static final StandardOpenOption TRUNCATE_EXISTING
If the file already exists and it is opened for WRITE access, then its length is truncated to 0. This option is ignored if the file is opened only for READ access.
If no options are present then this method works as if the CREATE, TRUNCATE_EXISTING, and WRITE options are present. In other words, it opens the file for writing, creating the file if it doesn't exist, or initially truncating an existing regular-file to a size of 0 if it exists.
Usage Examples:
Path path = ...
// truncate and overwrite an existing file, or create the file if
// it doesn't initially exist
OutputStream out = Files.newOutputStream(path);
// append to an existing file, fail if the file does not exist
out = Files.newOutputStream(path, APPEND);
// append to an existing file, create file if it doesn't initially exist
out = Files.newOutputStream(path, CREATE, APPEND);
// always create new file, failing if it already exists
out = Files.newOutputStream(path, CREATE_NEW);
Sybex:
Create a new file if it does not exist.
JavaDocs:
public static final StandardOpenOption CREATE
Create a new file if it does not exist. This option is ignored if the CREATE_NEW option is also set. The check for the existence of the file and the creation of the file if it does not exist is atomic with respect to other file system operations.
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
Campbell Ritchie wrote:I presume you have been through the Java™ Tutorials.
WRITE – Opens the file for write access.
APPEND – Appends the new data to the end of the file. This option is used with the WRITE or CREATE options.
TRUNCATE_EXISTING – Truncates the file to zero bytes. This option is used with the WRITE option.
CREATE_NEW – Creates a new file and throws an exception if the file already exists.
CREATE – Opens the file if it exists or creates a new file if it does not.
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
APPEND If the file is already open for write then append to the end.
TRUNCATE_EXISTING If file is already open for write then erase file and append to beginning.
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
Don't do anything; I can add this thread to a secondary forum in a few seconds.Jesse Silverman wrote:. . . cross-posted in the Certifications forum . . .
Unfortunately the Java™ Tutorials are very laconic on some subjects; this is obviously one of themThe tutorial phrases it best of the bunch, but still needs these examples . . .
Yes, I see what you mean. I think APPEND says, “if,” when it should say, “whether,” too. Also, the documentation is definitive; if there are any discrepancies between that and the Java™ Tutorials, you must assume the Java™ Tutorials are in error.The Javadocs were more confusing than the tutorial . . .
If the file already exists and it is opened for WRITE access,
If the file already exists and it is being opened for WRITE access,
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
My cellmate was this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|