Java File Base Name Get baseName(String name)

Here you can find the source of baseName(String name)

Description

Search for both slashes in order to support URLs and files.

License

Open Source License

Declaration

public static String baseName(String name) 

Method Source Code

//package com.java2s;
/*//from  w  w w  . j a  v  a2  s . c  o m
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {
    /**
     * Search for both slashes in order to support URLs and
     * files.
     */
    public static String baseName(String name) {
        int index = name.lastIndexOf('\\');
        if (index < 0) {
            index = name.lastIndexOf('/');
        }

        if (index >= 0)
            return name.substring(index + 1);
        else {
            int lastColonIndex = name.lastIndexOf(':');
            if (lastColonIndex > 0)
                return name.substring(lastColonIndex + 1);
            else
                return name;
        }
    }
}

Related

  1. baseName(String filename)
  2. baseName(String filename)
  3. baseName(String filename)
  4. basename(String filename)
  5. baseName(String fn)
  6. basename(String name, String split)
  7. basename(String path)
  8. basename(String path)
  9. basename(String path)