Path implements IOReadableWritable, Serializable { public String getName() { final String path = uri.getPath(); final int slash = path.lastIndexOf(SEPARATOR); return path.substring(slash + 1); } Path();  Path(URI uri);  Path(String parent, String child);  Path(Path parent, String child);  Path(String parent, Path child);  Path(Path parent, Path child);  Path(String pathString);  Path(String scheme, String authority, String path); URI toUri(); FileSystem getFileSystem(); boolean isAbsolute(); String getName(); String getPath(); Path getParent(); Path suffix(String suffix); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); int compareTo(Object o); int depth(); Path makeQualified(FileSystem fs); @Override void read(DataInputView in); @Override void write(DataOutputView out); boolean hasWindowsDrive(); static final String SEPARATOR; static final char SEPARATOR_CHAR; static final String CUR_DIR; }
@Test public void testGetName() { Path p = new Path("/my/fancy/path"); assertEquals("path", p.getName()); p = new Path("/my/fancy/path/"); assertEquals("path", p.getName()); p = new Path("hdfs: assertEquals("path", p.getName()); p = new Path("hdfs: assertEquals("myPath", p.getName()); p = new Path("/"); assertEquals("", p.getName()); p = new Path("C:/my/windows/path"); assertEquals("path", p.getName()); p = new Path("file:/C:/my/windows/path"); assertEquals("path", p.getName()); }