Here you can find the source of canonicalpath(String path, boolean relative)
Parameter | Description |
---|---|
path | convert this path |
static public String canonicalpath(String path, boolean relative)
//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; } }