title: Java create multiple new files
body: <p>I read this question here <a href="https://stackoverflow.com/questions/6142901/how-to-create-a-file-in-a-directory-in-java">How to create a file in a directory in java?</a></p>
  
  <p>I have a method that creates a QR Code. The method is called several times, depends on user input. </p>
  
  <p>This is a code snippet: </p>
  
  <pre><code>String filePath = "/Users/Test/qrCODE.png";
  int size = 250;
  //tbd
  String fileType = "png";
  File myFile = new File(filePath);
  </code></pre>
  
  <p>The problem: If the user types "2" then this method will be triggered twice. 
  As a result, the first qrCODE.png file will be replaced with the second qrCODE.png, so the first one is lost.</p>
  
  <p>How can I generate more than one qr code with different names, like qrCODE.png and qrCODE(2).png </p>
  
  <p>My idea: </p>
  
  <pre><code>if (!myFile.exists()) {
      try {
          myFile.createNewFile();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Any tips? </p>
  
  <p><strong>EDIT: I solved it by using a for loop and incrementing the number in the filename in every loop step.</strong></p>