Here you can find the source of extractFileNameWithSuffix(String filePathName)
Parameter | Description |
---|---|
filePathName | the file name with path and suffix |
public static String extractFileNameWithSuffix(String filePathName)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004 Actuate Corporation. * 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://from w w w. j av a 2 s .co m * Actuate Corporation - initial API and implementation *******************************************************************************/ public class Main { /** * Extract file name (without path but with suffix) from file name with path and * suffix. * <p> * For example: * <p> * <ul> * <li>"c:\home\abc.xml" => "abc.xml" * <li>"c:\home\abc" => "abc" * <li>"/home/user/abc.xml" => "abc.xml" * <li>"/home/user/abc" => "abc" * </ul> * * @param filePathName * the file name with path and suffix * @return the file name without path but with suffix */ public static String extractFileNameWithSuffix(String filePathName) { if (filePathName == null) return null; int slashPos = filePathName.lastIndexOf('\\'); if (slashPos == -1) slashPos = filePathName.lastIndexOf('/'); return filePathName.substring(slashPos > 0 ? slashPos + 1 : 0); } }