Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

...

Code Block
bgColor#ffcccc
langjava
public void noAlter_ncecreateFile(String filename) throws FileNotFoundException{
  OutputStream out = new FileOutputStream(filename, true);
  if (!new File(filename).createNewFile()) {
      // File cannot be created...handle error
  } else {
      OutputStream out = new FileOutputStream(filename);
      // Work with FILE
  }
} 

...

Code Block
bgColor#ccccff
langjava
public void createFile_cs(String filename) throws FileNotFoundException{
  try (OutputStream out = new BufferedOutputStream(
    Files.newOutputStream(Paths.get(filename),
                          StandardOpenOption.CREATE_NEW))) {
    // Work with out
  } catch (IOException x) {
      // File not writable...handle error
  }
} 

...