Here you can find the source of getFileExtension(String fileName)
Parameter | Description |
---|---|
fileName | a parameter |
public static String getFileExtension(String fileName)
//package com.java2s; /*//from w ww . j av a2s . c om * Copyright (c) 2012 Diamond Light Source Ltd. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ import java.io.File; public class Main { /** * Get File extension (result will NOT include ".") * * @param fileName * @return String file extension value, or "" is no extension */ public static String getFileExtension(String fileName) { int posExt = fileName.lastIndexOf("."); // No File Extension return posExt == -1 ? "" : fileName.substring(posExt + 1); } /** * Get File extension (result will NOT include ".") * * @param file * @return String file extension value, or "" is no extension */ public static String getFileExtension(File file) { return getFileExtension(file.getName()); } }