Java Path Normalize normalizePath(final String path)

Here you can find the source of normalizePath(final String path)

Description

Removes any extra path separators and converts all from back slashes to forward slashes.

License

BSD License

Parameter

Parameter Description
path the path to normalize.

Return

the normalizd path

Declaration

public static String normalizePath(final String path) 

Method Source Code

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

public class Main {
    /**/*from  w  w  w  .j  a v a2  s.  c  o  m*/
     * The forward slash character.
     */
    private static final String FORWARD_SLASH = "/";
    /**
     * The pattern used for normalizing paths paths with more than one back slash.
     */
    private static final String BACK_SLASH_NORMALIZATION_PATTERN = "\\\\+";
    /**
     * The pattern used for normalizing paths with more than one forward slash.
     */
    private static final String FORWARD_SLASH_NORMALIZATION_PATTERN = FORWARD_SLASH + '+';

    /**
     * Removes any extra path separators and converts all from back slashes
     * to forward slashes.
     *
     * @param path the path to normalize.
     * @return the normalizd path
     */
    public static String normalizePath(final String path) {
        return path != null ? path.replaceAll(BACK_SLASH_NORMALIZATION_PATTERN, FORWARD_SLASH)
                .replaceAll(FORWARD_SLASH_NORMALIZATION_PATTERN, FORWARD_SLASH) : null;
    }
}

Related

  1. normalizeName(final String path, final boolean isDirectory)
  2. NormalizeName(String absolutePath)
  3. normalizePath(final String in)
  4. normalizePath(final String path)
  5. normalizePath(final String path)
  6. normalizePath(final String path)
  7. normalizePath(final String... path)
  8. normalizePath(String _path, boolean _appendFinalSeparator)
  9. normalizePath(String absPath)