Java Path Normalize normalize(String path)

Here you can find the source of normalize(String path)

Description

Normalizes the given path (removes superfluous #SEPARATOR separators ).

License

Apache License

Parameter

Parameter Description
path the path to be normalized

Return

the normalized path

Declaration

public static String normalize(String path) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*w  w  w  .ja  va  2  s .  c  o m*/
     * The separator between element names.
     */
    public static final String SEPARATOR = "/";

    /**
     * Normalizes the given path (removes superfluous {@link #SEPARATOR separators}).
     * 
     * @param path the path to be normalized
     * @return the normalized path
     */
    public static String normalize(String path) {
        path = path.replace(SEPARATOR + SEPARATOR, SEPARATOR);
        if (path.startsWith(SEPARATOR)) {
            path = path.substring(1);
        }
        if (path.endsWith(SEPARATOR)) {
            path = path.substring(0, path.length() - 1);
        }
        return path;
    }
}

Related

  1. normalize(final boolean absolutize, final String... path)
  2. normalize(final String path)
  3. normalize(final String path)
  4. normalize(final String path)
  5. normalize(final String pathname)
  6. normalize(String path)
  7. normalize(String path)
  8. normalize(String path)
  9. normalize(String path)