Here you can find the source of getFileName(File file)
public static String getFileName(File file)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.regex.Pattern; public class Main { public static String getFileName(File file) { String filename;// ww w . j av a 2 s. co m String[] parts = file.toString().split(Pattern.quote("\\")); filename = parts[parts.length - 1]; //filename including extension String[] segs = filename.split(Pattern.quote(".")); filename = segs[segs.length - 2]; return filename; } public static String getFileName(String filename) { String[] parts = filename.toString().split(Pattern.quote("\\")); filename = parts[parts.length - 1]; //filename including extension String[] segs = filename.split(Pattern.quote(".")); filename = segs[segs.length - 2]; return filename; } }