Here you can find the source of basename(String path, char separator)
Parameter | Description |
---|---|
path | path |
separator | separator |
public static String basename(String path, char separator)
//package com.java2s; /* ========================================================================== * * Copyright (C) 2004-2005 Pier Fumagalli <http://www.betaversion.org/~pier/> * * All rights reserved. * * ========================================================================== * * * * Licensed under the Apache License, Version 2.0 (the "License"). You may * * not use this file except in compliance with the License. You may obtain a * * copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>. * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * * License for the specific language governing permissions and limitations * * under the License. * * * * ========================================================================== */ public class Main { /**// w w w . j av a 2s.c om * Strips the directory from a file path (if any) using the specified * character as a separator. If an empty path is supplied then an empty is * returned. * * @param path path * @param separator separator * @return path */ public static String basename(String path, char separator) { if (path.equals("")) { return path; } while (path.endsWith(String.valueOf(separator))) { path = path.substring(0, path.length() - 1); } int idx = path.lastIndexOf(separator); return idx == -1 ? path : path.substring(idx + 1); } }