Here you can find the source of normalizePath(String path)
Parameter | Description |
---|---|
path | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static String normalizePath(String path) throws Exception
//package com.java2s; /*************************************************************************************** * Copyright (C) 2007 Samatar. All rights reserved. * This software was developed by Samatar and is provided under the terms * of the GNU Lesser General Public License, Version 2.1. You may not use * this file except in compliance with the license. A copy of the license, * is included with the binaries and source code. The Original Code is Samatar. * The Initial Developer is Samatar.//from ww w. j a va 2 s. c o m * * Software distributed under the GNU Lesser Public License is distributed on an * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. * Please refer to the license for the specific language governing your rights * and limitations. ***************************************************************************************/ public class Main { public static String FILE_SEPARATOR = "/"; /** * normalize / to \ and remove trailing slashes from a path * * @param path * @return normalized path * @throws Exception */ public static String normalizePath(String path) throws Exception { if (path == null) return path; String normalizedPath = path.replaceAll("\\\\", FILE_SEPARATOR); while (normalizedPath.endsWith("\\") || normalizedPath.endsWith(FILE_SEPARATOR)) { normalizedPath = normalizedPath.substring(0, normalizedPath.length() - 1); } return normalizedPath; } }