Java Path Normalize normalizePath(String path, String oldFileSeperator, String newFileSeparator)

Here you can find the source of normalizePath(String path, String oldFileSeperator, String newFileSeparator)

Description

normalize Path

License

Apache License

Declaration

public static String normalizePath(String path, String oldFileSeperator, String newFileSeparator) 

Method Source Code

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

public class Main {
    public static String normalizePath(String path) {
        String fileSeparator = System.getProperty("file.separator");
        String newPath = null;//from w  w w .j a v  a 2  s  .com
        if (fileSeparator.equals("\\"))
            newPath = normalizePath(path, "/", fileSeparator);
        else
            newPath = normalizePath(path, "\\", "/");
        if (newPath.contains(fileSeparator + fileSeparator))
            newPath = newPath.replace(fileSeparator + fileSeparator, fileSeparator);
        return newPath;
    }

    public static String normalizePath(String path, String oldFileSeperator, String newFileSeparator) {
        boolean containsDrive = path.contains(":");
        String newPath = path.replace(oldFileSeperator, newFileSeparator);
        if (containsDrive) {
            if (newPath.substring(0, 1).equals(newFileSeparator))
                newPath = newPath.substring(1);
        }
        return newPath;
    }
}

Related

  1. normalizePath(String path)
  2. normalizePath(String path)
  3. normalizePath(String path)
  4. normalizePath(String path)
  5. normalizePath(String path, char sep)
  6. normalizePath(String path, String separator)
  7. normalizePath(String pathFragment)
  8. normalizePath(String pathname)
  9. normalizePathElement(String name)