Java Path String Clean cleanPath(String path)

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

Description

clean path, remove double "/" and replace "\" by "/"

License

LGPL

Parameter

Parameter Description
path a parameter

Return

"//web/path" >> "/web/path"

Declaration

public static String cleanPath(String path) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**//from w w w . ja va  2  s. co  m
      * clean path, remove double "/" and replace "\" by "/"
      * 
      * @param path
      * @return "//web/path" >> "/web/path"
      */
    public static String cleanPath(String path) {
        if (path == null) {
            return null;
        } else {
            path = path.replace('\\', '/');
            while (path.indexOf("//") >= 0) {
                path = path.replace("//", "/");
            }
            return path;
        }

    }
}

Related

  1. cleanPath(final String path)
  2. cleanPath(final String url)
  3. cleanPath(String loc)
  4. cleanPath(String path)
  5. cleanPath(String path)
  6. cleanPath(String path)
  7. cleanPath(String path)
  8. cleanPath(String path)