Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8331316

(fs) Provide a java.nio.file.Files.createFileIfAbsent()

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      `Files` provides a convenient utility method for creating a new file, `Files.createFile`. However, if you need to ensure that a certain file is in place and don't mind if it already exists, you have to resort to manual checks before calling the method
      ```java
      // for example, like so

      @SneakyThrows
      void createFileIfAbsent() {
      Path path = Paths.get("text.txt");
      if (!path.toFile().exists()) {
      Files.createFile(path);
      }
      }
      ```
      It would be more convenient if `Files` *itself* provided such functionality with a `createFileIfAbsent()` method


            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: