Java Path Normalize normalise(String path)

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

Description

normalise

License

Open Source License

Declaration

public static final String normalise(String path) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public final static char SLASH_CHAR = '/';
    public final static char BACK_SLASH_CHAR = '\\';

    public static final String normalise(String path) {
        return normalise(path, BACK_SLASH_CHAR, SLASH_CHAR);
    }//w  ww  .ja  va  2 s  .  co m

    public static final String normalise(String path, char separator) {
        return normalise(path, separator, separator);
    }

    public static final String normalise(String path, char separator, char newSeparator) {
        if (path != null) {
            String p = path.trim();
            if (separator != newSeparator) {
                p = p.replace(separator, newSeparator);
            }
            p.replaceAll("\\" + newSeparator + "{2,}", "\\" + newSeparator);
            return p;
        }
        return null;
    }
}

Related

  1. normalisePath(final String path)
  2. normalisePath(String path)
  3. normalisePath(String path)
  4. normalize(final boolean absolutize, final String... path)