Java Path String Clean filePathTail(String filePath)

Here you can find the source of filePathTail(String filePath)

Description

returns the component of the url after the last / OR \

License

Apache License

Declaration

public static String filePathTail(String filePath) 

Method Source Code

//package com.java2s;
/*//from w  w  w .j a  va2  s  . c  om
 Copyright (C) 2012 The Stanford MobiSocial Laboratory
    
   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 {
    /** returns the component of the url after the last / OR \
     */
    public static String filePathTail(String filePath) {
        String t = tail(filePath, "/");
        t = tail(t, "\\");
        return t;
    }

    public static String tail(String s, String separator) {
        if (s == null)
            return null;
        int idx = s.lastIndexOf(separator);
        if (idx >= 0)
            return s.substring(idx + 1);
        else
            return s;
    }
}

Related

  1. cleanPath(String path, boolean trimStartSeparator)
  2. cleanPath(String s)
  3. cleanPath(String sText, boolean isWindows)
  4. cleanPathSegment(final String toClean)
  5. filePathReplaceAll(String value)