Java Path String Clean cleanPath(String path)

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

Description

Removes a trailing path separator.

License

Open Source License

Parameter

Parameter Description
path A path that could end in a slash or backslash.

Return

The same path without the trailing path separator.

Declaration

protected static synchronized String cleanPath(String path) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000, 2014 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * //from  w w  w.j a  v a2 s .c  o m
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Removes a trailing path separator.
     * @param path A path that could end in a slash or backslash.
     * @return The same path without the trailing path separator.
     */
    protected static synchronized String cleanPath(String path) {
        String slash = System.getProperty("file.separator");
        if (slash != null && slash.length() > 0) {
            int len = path.length();
            if (len > 0 && path.charAt(len - 1) == slash.charAt(0)) {
                return path.substring(0, len - 1);
            }
        }
        return path;
    }
}

Related

  1. cleanPath(String path)
  2. cleanPath(String path)
  3. cleanPath(String path)
  4. cleanPath(String path)
  5. cleanPath(String path)
  6. cleanPath(String path)
  7. cleanPath(String path, boolean trimStartSeparator)
  8. cleanPath(String s)
  9. cleanPath(String sText, boolean isWindows)