Java tutorial
//package com.java2s; public class Main { /** * Gets the final component from a path. This assumes that path components * are separated by forward slashes. * * @param path The path to apply the basename operation to. * @return path, with any leading directory elements removed */ public static String basename(String path) { if (path.length() == 0) { return path; } int pos = path.lastIndexOf("/"); if (pos == -1) { return path; } else { return path.substring(pos + 1); } } }