Java Path Create Canonical canonicalpath(String path, boolean relative)

Here you can find the source of canonicalpath(String path, boolean relative)

Description

Convert path to: 1.

License

Open Source License

Parameter

Parameter Description
path convert this path

Return

canonicalized version

Declaration

static public String canonicalpath(String path, boolean relative) 

Method Source Code

//package com.java2s;
/* Copyright 2012, UCAR/Unidata.
 See the LICENSE file for more information. */

public class Main {
    /**/*from   w  w w  . j a  v  a2  s  .  c  o m*/
     * Convert path to:
     * 1. use '/' consistently
     * 2. remove any trailing '/'
     * 3. trim blanks
     *
     * @param path convert this path
     * @return canonicalized version
     */
    static public String canonicalpath(String path, boolean relative) {
        if (path == null)
            return null;
        path = path.trim();
        path = path.replace('\\', '/');
        if (path.endsWith("/"))
            path = path.substring(0, path.length() - 1);
        if (relative && path.startsWith("/"))
            path = path.substring(1);
        return path;
    }
}

Related

  1. canonicalPath(String orig)
  2. canonicalpath(String path)
  3. canonicalPath(String path)