Here you can find the source of getParentNameofPath(String path)
public static String getParentNameofPath(String path)
//package com.java2s; public class Main { public static String getParentNameofPath(String path) { if (path.equals("/")) { return null; }/*from w w w . j av a 2 s. c o m*/ if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } int index = path.lastIndexOf('/'); if (path.length() == 1) { return path; } if (index == 0) { return "/"; } return path.substring(0, index); } }