Here you can find the source of normalizeFullPath(String path)
Parameter | Description |
---|---|
path | The path to operate on. |
public static final String normalizeFullPath(String path)
//package com.java2s; /*//ww w. j a v a 2s . c o m * Copyright (c) 1998-2017 by Richard A. Wilkes. All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, version 2.0. If a copy of the MPL was not distributed with * this file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This Source Code Form is "Incompatible With Secondary Licenses", as * defined by the Mozilla Public License, version 2.0. */ public class Main { /** * Normalizes full path names by resolving . and .. path portions. * * @param path The path to operate on. * @return The normalized path. */ public static final String normalizeFullPath(String path) { if (path != null) { int index; StringBuilder buffer; char ch; path = path.replace('\\', '/'); do { index = path.indexOf("/./"); if (index != -1) { buffer = new StringBuilder(path); buffer.delete(index, index + 2); path = buffer.toString(); } } while (index != -1); do { index = path.indexOf("/../"); if (index != -1) { int length = 3; buffer = new StringBuilder(path); while (index > 0) { ch = buffer.charAt(--index); length++; if (ch == '/') { break; } else if (ch == ':') { index++; length--; break; } } buffer.delete(index, index + length); path = buffer.toString(); } } while (index != -1); if (path.endsWith("/.")) { path = path.substring(0, path.length() - 2); } if (path.endsWith("/..")) { index = path.length() - 3; while (index > 0) { ch = path.charAt(--index); if (ch == '/' || ch == ':') { break; } } path = path.substring(0, index); } if (path.length() > 1 && path.charAt(1) == ':') { path = Character.toUpperCase(path.charAt(0)) + ":" + path.substring(2); } } return path; } }