Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: deleted append nce

...

If the file existed before being opened, its former contents will be overwritten with the contents provided by the program.

Noncompliant Code Example (

...

This noncompliant code example tries to avoid overwriting an existing file:

Code Block
bgColor#ffcccc
langjava
public void noOverwrite_nce(String filename) throws FileNotFoundException{
  OutputStream out = new FileOutputStream(filename, true);
  // Work with FILE
}

If the file existed before being opened, any new data written out will be appended to the former contents. This code is compliant only if this behavior matches the intent of the programmer.

Noncompliant Code Example (TOCTOU)

This noncompliant code example tries to avoid altering an existing file by creating an empty file using java.io.File.createNewfile(). If a file with the given name already exists, then createNewFile() will return false.

...