Here you can find the source of getFileExtension(String filePath)
Parameter | Description |
---|---|
filePath | The file path |
public static String getFileExtension(String filePath)
//package com.java2s; /* Copyright 2012 Yaqiang Wang, * yaqiang.wang@gmail.com// w w w . j av a 2 s .c o m * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or (at * your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * General Public License for more details. */ import java.io.File; public class Main { /** * Get file extension * * @param filePath The file path * @return File extension */ public static String getFileExtension(String filePath) { String extension = ""; String fn = new File(filePath).getName(); if (fn.contains(".")) { String ext = filePath.substring(filePath.lastIndexOf(".") + 1).toLowerCase().trim(); try { extension = ext; } catch (IllegalArgumentException e) { } } return extension; } }