Here you can find the source of getFileExtension(File file)
Parameter | Description |
---|---|
file | The file in which the extension must be extracted. |
public static String getFileExtension(File file)
//package com.java2s; import java.io.File; public class Main { /**/*from w ww .jav a 2 s .co m*/ * Gets the file extension as a string. For example, given the file "test.xml", * the result of this method consists of "xml". Notice that if no extension is * found in the file, the string returned is empty. * * @param file The file in which the extension must be extracted. * @return The extension of a given file as a string. */ public static String getFileExtension(File file) { String fileName = file.getName(); return (fileName.lastIndexOf(".") == -1) ? "" : fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()); } /** * Gets the file extension as a string. For example, given the file "test.xml", * the result of this method consists of "xml". Notice that if no extension is * found in the file, the string returned is empty. * * @param filefileName the name of the file. * @return The extension of a given file name as a string. */ //INSPECT - Lais New Method public static String getFileExtension(String fileName) { return (fileName.lastIndexOf(".") == -1) ? "" : fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()); } }