title: Java - How to find out whether a File name is valid?
body: <p>In my Java application I am renaming files to a file name provided in a String parameter. There is a method</p>
  
  <pre><code>boolean OKtoRename(String oldName, String newName)
  </code></pre>
  
  <p>which basically checks whether the newName isn't already taken by some other file, as I wouldn't want to bury existing ones.</p>
  
  <p>It now occurred to me that perhaps the newName String will not denote a valid file name. So I thought to add this check to the method:</p>
  
  <pre><code>if (new File(newName).isFile()) { 
      return false; 
  }
  </code></pre>
  
  <p>Which obviously isn't the right way to do it, since in most cases the newFile does not yet exist and therefore although it <em>is</em> OKtoRename, the function returns false.</p>
  
  <p>I was wondering, is there a method (I know there isn't for the java.io.File objects) like <code>canExist()</code>? Or would I have to resort to regex to make sure the newFile String does not contain invalid characters (e.g. ?, *, ", :)? I wonder if there is perhaps a function hidden somewhere in the JDK that would tell me if a string could possibly denote a valid file name.</p>