/** * Gets the extension of the specified file name. * * @param fileName * A file name. * @return The file name extension (e.g. "exe" or "txt"), or <tt>null</tt> * if the file name does not have a (valid) extension. */ public static String getFileExtension(String fileName) { int lastDotIdx = fileName.lastIndexOf('.'); if (lastDotIdx > 0 && lastDotIdx < fileName.length() - 1) { String extension = fileName.substring(lastDotIdx + 1).trim(); if (isLegalFileName(extension)) { return extension; } } return null; }