FilepathUtils { public static String getFilename(final String path) { if (null == path) { return null; } final String canonicalPath = getCanonicalForm(path); final int index = canonicalPath.lastIndexOf(DIRECTORY_SEPARATOR); return (index < 0) ? canonicalPath : canonicalPath.substring(index + 1); }  static String[] getCanonicalFragments(final String path); static String getCanonicalForm(final String path); static String[] split(final String path); static String getParentPath(final String path); static String getFilename(final String path); static String concat(final String... fragments); static String append(final String... fragments); static String append(final String[] fragments, final int start, final int end);  }
@Test public void testGetFilename() { final Object[][] testParameters = new Object[][] {{"/tester.jpg", "tester.jpg"}, {"/Users/admin/admin.jpg", "admin.jpg"}, {"/Users/tester/alphatester/../../admin.jpg", "admin.jpg"}, {"/Users/tester/betatester/../../tester.jpg", "tester.jpg"}}; assertNull(FilepathUtils.getFilename(null)); for (final Object[] testParameter : testParameters) { String expected = (String) testParameter[1]; String path = (String) testParameter[0]; assertEquals(expected, FilepathUtils.getFilename(path)); } }