title: How to encode a filepath in a filename? (no collisions, crossplatform)
body: <p>How can I encode a filepath in filename so the filename is valid and there are no collisions? In other words:</p>
  
  <ul>
  <li>The resulting filename does not contain special characters such as '\', ':' or '/'.</li>
  <li>Two different filepaths are never encoded into the same filename.</li>
  </ul>
  
  <p>Example: filepath "C:\Program Files\My Program" -> filename "NGQqKY4pBaP7lPKQPD6Y..."</p>
  
  <p>This example is only for illustration; there may be better (and simpler) ways to do this.</p>
  
  <p>Problem background: This filepath encoding is used for a simple single-instance-check in Java: Two instances of the program can be run simultaneously if they are located in different directories, but not when they are located in the exact same directory.
  I know there are other ways to ensure the single-instance property, but I find the filepath encoding to be the best in terms of cost-benefit-ratio in my particular situation.</p>