title: How to retrieve forbidden characters for filenames, in Java?
body: <p>There are some restricted characters (and even full filenames, in Windows), for file and directory names. This <a href="https://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names">other question</a> covers them already.</p>
  
  <p>Is there a way, in Java, to retrieve this list of forbidden characters, which would be depending on the system (a bit like retrieving the line breaker chars)? Or can I only put the list myself, checking for the system?</p>
  
  <hr>
  
  <p><strong>Edit:</strong> More background on my particular situation, aside from the general question. </p>
  
  <p>I use a default name, coming from some data (no real control over their content), and this name is given to a JFileChooser, as a default file name to use (with <code>setSelectedFile()</code>). However, this one truncates anything prior to the last invalid character. </p>
  
  <p>These default names occasionally end with dates in a "mm/dd/yy" format, which leaves only the "yy", in the default name, because "/" are forbidden. As such, checking for Exceptions is not really an option there, because the file itself is not even created yet. </p>
  
  <p><strong>Edit bis:</strong> Hmm, that makes me think, if JFileChooser is truncating the name, it probably has access to a list of such characters, can be interesting to check that further.</p>
  
  <p><strong>Edit ter:</strong> Ok, checking sources from JFileChooser shows something completely simple. For the text field, it uses file.getName(). It doesn't actually check for invalid characters, it's simply that it takes the "/" as a path separator, and keeps only the end, the "actual filename". Other forbidden characters actually go through.</p>