Here you can find the source of extractFileName(String path)
Parameter | Description |
---|---|
path | absolute or relative path with forward slashes as delimiters |
static public String extractFileName(String path)
//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:/*from www . j a va 2 s . c o m*/ * ARM Ltd and ARM Germany GmbH - Initial API and implementation *******************************************************************************/ public class Main { /** * Extracts filename portion out of supplied pathname (leaves last segment only) * @param path absolute or relative path with forward slashes as delimiters * @return the result filename */ static public String extractFileName(String path) { if (path == null || path.isEmpty()) return path; int pos = path.lastIndexOf('/'); if (pos < 0) pos = path.lastIndexOf('\\'); if (pos >= 0) return path.substring(pos + 1); return path; } }