/** * Returns the filename, without any extension. (Eg. /tmp/foo.txt -> /tmp/foo) * * @param file * @return the basename */ public static String getBasename( File file ) { return splitFilename( file ).first; }
/** * Returns the file extension (Eg. /tmp/foo.txt -> txt) * * @param file * @return the file extension */ public static String getFileExtension( File file ) { return splitFilename( file ).second; }
/** * Returns the filename, without any extension and path (Eg. /tmp/foo.txt -> foo) * * @param file * @return the basename or <code>null</code> if the file is null; */ public static String getFilename( File file ) { if ( file == null ) { return null; } String path = splitFilename( file ).first; String parent = file.getParent(); return ( parent != null ) ? ( path.substring( file.getParent().length() + 1 ) ) : path; }