usmanazizgroupdocs
4/15/2016 - 10:35 AM

GetFileExtension.java

// For complete examples and data files, please go to https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-Java
/**
 * This method gets extension of file
 * 
 * @param fileName
 *            name of the file
 * @return String file extension
 */
public static String getFileExtension(String fileName) {
	try {

		// Get file name tokens
		String[] tokens = fileName.split("\\.(?=[^\\.]+$)");

		// Return file extension
		return tokens[tokens.length - 1];
	} catch (Exception exp) {
		System.out.println("Exception: " + exp.getMessage());
		exp.printStackTrace();
		return null;
	}

}