Here you can find the source of getFileExtension(File _file)
Parameter | Description |
---|---|
_file | file |
public static String getFileExtension(File _file)
//package com.java2s; //License from project: Open Source License import java.io.File; public class Main { /**// w ww . jav a 2 s.c o m * Extracts the file extension (part behind last dot of a filename). * Only returns the extension, without the leading dot. * * @param _fileName filename * @return extension, empty string if no dot was found in filename or null if given String was null */ public static String getFileExtension(String _fileName) { if (_fileName == null) { return null; } int lastDot = _fileName.lastIndexOf('.'); if (lastDot == -1) { return ""; } return _fileName.substring(lastDot + 1); } /** * Extracts the file extension (part behind last dot of a filename). * Only returns the extension, without the leading dot. * * @param _file file * @return extension, empty string if no dot was found in filename or null if given String was null */ public static String getFileExtension(File _file) { return getFileExtension(_file.getAbsolutePath()); } }