Java Path Normalize normalizePath(String path)

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

Description

Normalizes a path by removing trailing slash, unless the path is the root path.

License

Open Source License

Parameter

Parameter Description
path the path to the directory or file

Declaration

public static String normalizePath(String path) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /**/* ww w  . ja va  2s. c  om*/
     * The root path of workspaces.
     */
    public static final String WORKSPACE_ROOT = "/";

    /**
     * Normalizes a path by removing trailing slash, unless the path is the root path.
     *
     * @param path the path to the directory or file
     */
    public static String normalizePath(String path) {
        if (WORKSPACE_ROOT.equals(path)) {
            return path;
        }
        if (path.isEmpty()) {
            return WORKSPACE_ROOT;
        }
        int maybeSlash = path.length() - 1;
        return path.charAt(maybeSlash) == '/' ? path.substring(0, maybeSlash) : 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)