Here you can find the source of extractFileExtension(String filename)
Parameter | Description |
---|---|
filename | absolute or relative filename with forward slashes as delimiters |
static public String extractFileExtension(String filename)
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 ARM Ltd. and others * 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 * * Contributors:// w w w . java 2 s.c o m * ARM Ltd and ARM Germany GmbH - Initial API and implementation *******************************************************************************/ public class Main { /** * Extracts file extension (leaves last segment only) * @param filename absolute or relative filename with forward slashes as delimiters * @return the result filename */ static public String extractFileExtension(String filename) { if (filename == null || filename.isEmpty()) return filename; int pos = filename.lastIndexOf('.'); if (pos >= 0) { return filename.substring(pos + 1); } return null; } }