Here you can find the source of getFileExtension(final String file)
Parameter | Description |
---|---|
file | to get extension of |
public static String getFileExtension(final String file)
//package com.java2s; /*/* w ww .ja v a2s . co m*/ * This file is part of the "STARDUST" project. * * (c) Fabian Keller <hello@fabian-keller.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import java.io.File; public class Main { /** * Returns the file extension of a file * * @param file to get extension of * @return file extension * @see http://stackoverflow.com/a/21974043/1262901 */ public static String getFileExtension(final File file) { return getFileExtension(file.getName()); } /** * Returns the file extension of a file * * @param file to get extension of * @return file extension * @see http://stackoverflow.com/a/21974043/1262901 */ public static String getFileExtension(final String file) { final int lastIndexOf = file.lastIndexOf('.'); if (lastIndexOf == -1) { return ""; // empty extension } return file.substring(lastIndexOf + 1); } }