Here you can find the source of getNameDelLastPath(String fileName)
public static String getNameDelLastPath(String fileName)
//package com.java2s; public class Main { public static String getNameDelLastPath(String fileName) { int point = getPathLastIndex(fileName); if (point == -1) { return fileName; } else {/*from ww w . j a va2 s .com*/ return fileName.substring(0, point); } } 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; } }