title: Creating a file in Java with a dynamic name, getting syntax is incorrect error
body: <p>I'm writing a simple Java app which basically logs the output of a serial device (kinda like PuttY). so far the streaming and displaying of data is working, I am moving into the file creation and writing part of the program and I was testing out some code i read about creating a file:</p>
  <pre><code>public void createNewFile() {
      SimpleDateFormat dateFormat = new SimpleDateFormat(&quot;yyyy-MM-dd-HH:mm:ss&quot;);
      String newFileName = dateFormat.format(System.currentTimeMillis());
      try {
          File newFile = new File(&quot;C:\\Boxtest-%s.txt&quot;,newFileName);
          boolean fvar = newFile.createNewFile();
          if (fvar) {
              System.out.println(&quot;File created successfully&quot;);
              updateStatus(&quot;File created successfully!&quot;);
          }
          else {
              System.out.println(&quot;File already present&quot;);
              updateStatus(&quot;File already exists&quot;);
          }
          
      } catch (IOException e) {
          System.out.println(&quot;Exception!&quot;);
          updateStatus(e.getLocalizedMessage());
      }
      
  }
  </code></pre>
  <p>When I look at my status for the error message I get the error &quot;The filename, directory name or volume label syntax is incorrect&quot;.<br />
  I assume this is due to the name of the file having a variable? (&quot;C:\Boxtest-%s&quot;, newFileName) but then how can I make it create a new file every time I start the button and use the current date/time in the file name to avoid overwriting older files?</p>