Java Path Normalize normalisePath(String path)

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

Description

This normalises a path to ensure it starts with / and does not end with /

License

Apache License

Parameter

Parameter Description
path The path to normalize

Return

The path or an empty string if given no path

Declaration

private static String normalisePath(String path) 

Method Source Code

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

public class Main {
    /**/*from w ww. j av  a2 s . c om*/
     * This normalises a path to ensure it starts with / and does not end with /
     * @param path The path to normalize
     * @return The path or an empty string if given no path
     */
    private static String normalisePath(String path) {
        if (path != null) {
            path = path.trim();
            if (path.endsWith("/")) {
                path = path.substring(0, path.length() - 1);
            }
            if (!path.isEmpty() && !path.startsWith("/")) {
                path = "/" + path;
            }

            return path;
        }
        return "";
    }
}

Related

  1. normalise(String path)
  2. normalisePath(final String path)
  3. normalisePath(String path)
  4. normalize(final boolean absolutize, final String... path)
  5. normalize(final String path)
  6. normalize(final String path)
  7. normalize(final String path)