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 absPath)
Normalizes path.
if (absPath.endsWith("/")) {
    return absPath.substring(0, absPath.length() - 1);
return absPath;
StringnormalizePath(String filepath)
Normalizes a file path by replacing various special path tokens (., .., etc.) with their canonical equivalents.
if (filepath.startsWith("./") || filepath.startsWith(".\\")) {
    filepath = filepath.substring(2);
filepath = filepath.replace("/./", "/");
filepath = filepath.replace("\\.\\", "\\");
int endPos = filepath.indexOf("/../");
while (endPos != -1) {
    int startPos = endPos - 1;
...
StringnormalizePath(String fileSystemPath)
Normalizes the filesystem paths so that we only see '/' for the path separator character regardless of host operating system.
return fileSystemPath.replaceAll("\\\\", "/").replace("//", "/");
StringnormalizePath(String path)
normalize Path
String nPath = path.startsWith("/") ? path : String.format("/%s", path);
if (!isRoot(nPath) && nPath.endsWith("/"))
    nPath = nPath.replaceAll("[/]+$", "");
return nPath;
StringnormalizePath(String path)
normalize Path
String result = path;
if (path != null) {
    result = path.substring(path.startsWith("/") ? 1 : 0,
            path.endsWith("/") && path.length() > 1 ? path.length() - 1 : path.length());
return result;
StringnormalizePath(String path)
Normalizes the path to make every path not end with "/".
if (path == null || path.equals("/")) {
    return path;
if (path.endsWith("/")) {
    path = path.substring(0, path.length() - 1);
return path;
StringnormalizePath(String path)
Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path after ".."
String normalized = path;
if (normalized.indexOf('\\') >= 0)
    normalized = normalized.replace('\\', '/');
if (!normalized.startsWith("/"))
    normalized = "/" + normalized;
while (true) {
    int index = normalized.indexOf("//");
    if (index < 0)
...
StringnormalizePath(String path)
normalize Path
StringBuilder ret = new StringBuilder();
int i = path.length() - 1;
int end;
int skipCnt = 0;
while (i >= 0 && (path.charAt(i) == '/' || path.charAt(i) == '\\')) {
    i--;
while (i >= 0) {
...
StringnormalizePath(String path)
Remove relative references and "mistakes" like double slashes from the path.
String result = path;
result = replace("//", "/", result);
result = replace("/./", "/", result);
result = result.replaceAll("/[^/]+/\\.\\./", "/");
return result;
StringnormalizePath(String path)
normalize Path
if (path != null) {
    if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
        if (!path.startsWith("\"")) {
            path = "\"" + path;
        if (!path.endsWith("\"")) {
            path = path + "\"";
    else {
        if (path.startsWith("\"")) {
            path = path.substring(1);
        if (path.endsWith("\"")) {
            path = path.substring(0, path.length() - 1);
return path;