Here you can find the source of getFileExtension(String fileName)
Parameter | Description |
---|---|
fileName | The name of the file. |
public static String getFileExtension(String fileName)
//package com.java2s; import java.io.*; public class Main { /**// w w w . ja v a2s. c om * Returns file's extention. * * @param fileName The name of the file. */ public static String getFileExtension(String fileName) { String ext = null; if (fileName.lastIndexOf(".") > 0 && fileName.lastIndexOf(".") < fileName.length()) { ext = fileName.substring(fileName.lastIndexOf(".") + 1); } return ext; } public static String getFileExtension(File f) { String ext = null; String s = f.getName(); int i = s.lastIndexOf('.'); if (i > 0 && i < s.length() - 1) { ext = s.substring(i + 1).toLowerCase(); } return ext; } }