Here you can find the source of getFileExtension(final String filenamePath)
public static String getFileExtension(final String filenamePath)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { public static String DIRECTORY_SEPARATOR = File.separator; /**/*from www.ja va2 s.c o m*/ * Retourniert Dateiendung (mit Punkt). Falls keine Endung gefunden wird, wird ein leerer String * retourniert. */ public static String getFileExtension(final String filenamePath) { String filename = getFilename(filenamePath); if (filename.lastIndexOf(".") > 0) { //$NON-NLS-1$ return filename.substring(filename.lastIndexOf("."), filename.length()); //$NON-NLS-1$ } return ""; //$NON-NLS-1$ } /** * Retourniert Dateinamen ohne Pfad als String */ public static String getFilename(final String filenamePath) { String correctFilenamePath = getCorrectSeparators(filenamePath); if (correctFilenamePath.indexOf(DIRECTORY_SEPARATOR) < 0) { return filenamePath; } return correctFilenamePath.substring(correctFilenamePath.lastIndexOf(DIRECTORY_SEPARATOR) + 1, correctFilenamePath.length()); } private static String getCorrectSeparators(final String pathOrFilename) { return pathOrFilename.replace("\\", DIRECTORY_SEPARATOR).replace("//", //$NON-NLS-1$ //$NON-NLS-2$ DIRECTORY_SEPARATOR).replace("/", DIRECTORY_SEPARATOR); //$NON-NLS-1$ } }