Java tutorial
//package com.java2s; import java.util.StringTokenizer; public class Main { private static String getPathBeforeLastInPathElement(String path) { StringTokenizer st = new StringTokenizer(path, "."); StringBuffer sb = new StringBuffer(); int cpt = st.countTokens(); // if (cpt==1) // return root; int i = cpt - 1; for (int j = 0; j < i; j++) { String token = st.nextToken(); sb.append(token); if (j != i - 1) sb.append("."); } return sb.toString(); // String last = getLastInPathElement(path); // path = StringUtils.substringBefore(path, last); // return } }