Here you can find the source of normalizePath(String path)
public static String normalizePath(String path)
//package com.java2s; //License from project: Open Source License public class Main { public static String normalizePath(String path) { char[] array = path.toCharArray(); StringBuffer sb = new StringBuffer(); boolean skipNextPathChar = false; int idx = 0; for (int i = 0; i < array.length; i++) { char c = array[i]; boolean isPathChar = isPathChar(c); if (isPathChar) { if (skipNextPathChar) continue; skipNextPathChar = true; } else { skipNextPathChar = false; }/*w w w.ja v a2s .c om*/ idx++; sb.append(c); } if (idx > 1) { char last = sb.charAt(idx - 1); if (isPathChar(last)) { return sb.substring(0, idx - 1); } } return sb.toString(); } public static boolean isPathChar(char c) { return c == '/' || c == '.'; } }