Here you can find the source of baseName(String filename)
public static String baseName(String filename)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w. ja va 2s . c o m*/ * Returns the basename of a filename. Does this by returning only the * portion of the string after the last slash or backslash character * (either one if both present). * * If null is given, or if the name ends in a slash or backslash, an empty * string is returned. Whitespace is trimmed from the returned name. */ public static String baseName(String filename) { if (filename == null) return ""; String basename = filename; int idx = basename.lastIndexOf('/'); if (idx >= 0) { idx++; if (basename.length() == idx) return ""; else basename = basename.substring(idx); } idx = basename.lastIndexOf('\\'); if (idx >= 0) { idx++; if (basename.length() == idx) return ""; else basename = basename.substring(idx); } return basename.trim(); } }