Here you can find the source of getFileExtension(String fileName)
Parameter | Description |
---|---|
fileName | the file name (can also be file path) to extract extension from |
public static String getFileExtension(String fileName)
//package com.java2s; import java.io.File; public class Main { /**//w w w.j ava 2s . c om * Returns the extension of the given file without leading dot symbol. * * @param fileName * the file name (can also be file path) to extract extension from * * @return the extension of the given file or an empty string if the file has no extension */ public static String getFileExtension(String fileName) { fileName = new File(fileName).getName(); int dotIndex = fileName.lastIndexOf('.'); if (dotIndex == -1) { return ""; } return fileName.substring(dotIndex + 1); } }