Java Utililty Methods Path Normalize

List of utility methods to do Path Normalize

Description

The list of methods to do Path Normalize are organized into topic(s).

Method

StringnormalizePath(String path, String oldFileSeperator, String newFileSeparator)
normalize Path
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;
StringnormalizePath(String path, String separator)
Adds a trailing separator if it does not exist in path.
return path.endsWith(separator) ? path : path + separator;
StringnormalizePath(String pathFragment)
Normalizes the input path to an absolute path prepending / and ensuring that the path does not end in /.
char[] source = pathFragment.toCharArray();
char[] normalized = new char[source.length + 1];
int i = 0;
int j = 0;
if (source[i] != '/') {
    normalized[j++] = '/';
boolean slash = false;
...
StringnormalizePath(String pathname)
Normalizes a path as per ; StringBuilder ibuf = new StringBuilder(pathname.length() + 1); if (pathname.charAt(0) != '/') { ibuf.append('/'); ibuf.append(pathname); ...
StringnormalizePathElement(String name)
normalize Path Element
return name.replace("/", "").replace("\\", "");
StringnormalizePathname(String pathname)
Replaces all backslashes with slash char.
return pathname.replaceAll("\\\\", "/");
StringnormalizePathPart(final String path)
normalize Path Part
String result = path.trim();
while (result.startsWith("/") && result.length() > 1) {
    result = result.substring(1);
return result.replace('\\', '/');
StringnormalizePaths(String path)
Normalizes the input path in the windows and unix world to the Java Representation
return path.replaceAll("\\\\", "/");
StringnormalizePathSeparator(final String path)

Makes sure a given path uses the slash character has path separator by replacing all backslashes.

return path.replace("\\", STD_SEPARATOR);
StringnormalizeRegex(String path)
normalize Regex
if (path == null)
    return null;
return path.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)");