FilenameUtils { public static String getName(final String path) { if (path == null || path.length() == 0) { return ""; } int unix = path.lastIndexOf("/"); int windows = path.lastIndexOf("\\"); int colon = path.lastIndexOf(":"); String cand = path.substring(Math.max(colon, Math.max(unix, windows))+1); if (cand.equals("..") || cand.equals(".")){ return ""; } return cand; }  static String normalize(final String name); static String getName(final String path); final static char[] RESERVED_FILENAME_CHARACTERS; }
@Test public void testGetName() throws Exception { testFilenameEquality("quick.ppt", "C:\\the\\quick.ppt"); testFilenameEquality("quick.ppt", "/the/quick.ppt"); testFilenameEquality("", "/the/quick/"); testFilenameEquality("", "~/the/quick testFilenameEquality("~~quick", "~~quick"); testFilenameEquality("quick.ppt", "quick.ppt"); testFilenameEquality("", " testFilenameEquality("", "C: testFilenameEquality("", ".."); testFilenameEquality("quick", "C: testFilenameEquality("file.ppt", "path:to:file.ppt" ); testFilenameEquality("HW.txt", "_1457338542/HW.txt" ); }