code: public static String addTrailingFileSep(String path) {
          String fs = System.getProperty("file.separator");
          String dblfs = fs + fs;
          int indexDblfs;
          while ((indexDblfs = path.indexOf(dblfs, 1)) >= 0) {
              path = path.substring(0, indexDblfs) +
                  path.substring(indexDblfs + fs.length());
          }
          if (!path.endsWith(fs))
              path += fs;
          return path;
      }
docs: Add a trailing file separator, if not found. Remove superfluous
  file separators if any. Preserve the front double file separator for
  UNC paths.
  
  @param path Path under consideration.
  @return String Properly constructed path string.