code: private static File getTempPath(String prefix, File parentDir) throws IOException {
          final int maxI = (int)Math.pow(10, NUM_DIGITS);
          String formatStr = "%s_%0"+NUM_DIGITS+"d";
          File path;
          int i;
          for (i=0; i<maxI; i++) {
              path = new File(parentDir, String.format(formatStr, prefix, i));
              if (!path.exists()) {
                  return path;
              }
          }
          // If we ran out of short file names, just create a long one
          path = File.createTempFile(prefix, "", parentDir);
          if (!path.delete()) {
              throw new RuntimeException("Could not delete temp file as expected: " + path);
          }
          return path;
      }
docs: Creates a file object of a currently available path, but does
  not create the file. This method is not thread safe.