Here you can find the source of extractFileName(String fn)
public static String extractFileName(String fn)
//package com.java2s; //License from project: Apache License public class Main { public static String extractFileName(String fn) { int j = lastIndexOfPathSeparator(fn); if (j == -1) { return fn; }// www . j a va 2 s. com return (fn.substring(j + 1)); } public static String extractFileName(String fn, boolean includeExt) { int j = lastIndexOfPathSeparator(fn); String s; if (j == -1) { s = fn; } else { s = fn.substring(j + 1); } if (!includeExt) { return excludeFileExt(s); } return s; } public static int lastIndexOfPathSeparator(String str) { if (str == null) return -1; int length = str.length(); for (int i = length - 1; i >= 0; i--) { char c = str.charAt(i); if (c == '/' || c == '\\') { return i; } } return -1; } public static final String excludeFileExt(String fn) { if (fn == null) return fn; int i = lastIndexOf(fn, '.'); if (i != -1) { fn = fn.substring(0, i); } return fn; } public static int lastIndexOf(String str, char ch) { if (str == null) return -1; int length = str.length(); for (int i = length - 1; i >= 0; i--) { if (str.charAt(i) == ch) { return i; } } return -1; } }