Here you can find the source of getNamePart(String fileName)
public static String getNamePart(String fileName)
//package com.java2s; public class Main { public static String getNamePart(String fileName) { int point = getPathLastIndex(fileName); int length = fileName.length(); if (point == -1) { return fileName; } else if (point == length - 1) { int secondPoint = getPathLastIndex(fileName, point - 1); if (secondPoint == -1) { if (length == 1) { return fileName; } else { return fileName.substring(0, point); }//from w ww . j a v a 2 s. c o m } else { return fileName.substring(secondPoint + 1, point); } } else { return fileName.substring(point + 1); } } public static int getPathLastIndex(String fileName) { int point = fileName.lastIndexOf('/'); if (point == -1) { point = fileName.lastIndexOf('\\'); } return point; } public static int getPathLastIndex(String fileName, int fromIndex) { int point = fileName.lastIndexOf('/', fromIndex); if (point == -1) { point = fileName.lastIndexOf('\\', fromIndex); } return point; } }