Java Path Normalize normalizePath(String path)

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

Description

normalize Path

License

Apache License

Declaration

public static String normalizePath(String path) 

Method Source Code

//package com.java2s;
/**/*from   w ww  .j  av  a2  s  .  c om*/
 * SlingBeans - NetBeans Sling plugin
 * https://github.com/jkan997/SlingBeans
 * Licensed under Apache 2.0 license
 * http://www.apache.org/licenses/LICENSE-2.0
 */

public class Main {
    public static String normalizePath(String path) {
        return normalizePath(path, false);
    }

    public static String normalizePath(String path, boolean absolute) {
        path = path.trim();
        if (path.startsWith("/")) {
            if (!absolute) {
                path = path.substring(1);
            }
        } else {
            if (absolute) {
                path = "/" + path;
            }
        }
        if (path.endsWith("/")) {
            path = path.substring(0, path.length() - 1);
        }
        return path;
    }
}

Related

  1. normalizePath(String path)
  2. normalizePath(String path)
  3. normalizePath(String path)
  4. normalizePath(String path)
  5. normalizePath(String path)
  6. normalizePath(String path)
  7. normalizePath(String path)
  8. normalizePath(String path)
  9. normalizePath(String path)