Java File Base Name Get basename(String filename)

Here you can find the source of basename(String filename)

Description

basename

License

Open Source License

Declaration

public static String basename(String filename) 

Method Source Code

//package com.java2s;

public class Main {
    public static String basename(String filename) {
        String result = filename;
        int p = result.lastIndexOf('/');
        if (p >= 0) {
            result = result.substring(p + 1);
        }//from   ww w.  j a v  a  2  s  .  c  om
        p = result.lastIndexOf('.');
        if (p >= 0) {
            result = result.substring(0, p);
        }
        return result;
    }

    public static String substring(StringBuffer buf, int start, int lim) {
        int len = lim - start;
        char[] result = new char[len];
        buf.getChars(start, lim, result, 0);
        return String.valueOf(result);
    }
}

Related

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