Here you can find the source of getFilename(String path)
public static String getFilename(String path)
//package com.java2s; /**/*from w ww . j av a 2 s . co m*/ * Source: http://stackoverflow.com/questions/453018/number-of-lines-in-a-file-in-java * Licensed under http://creativecommons.org/licenses/by-sa/3.0/ */ import java.io.File; public class Main { public static String getFilename(String path) { return getFilename(path, File.separator); } public static String getFilename(String path, String separator) { int filenameStart = path.lastIndexOf(separator); if (filenameStart != -1) { filenameStart += 1; // move cursor after dot return path.substring(filenameStart); } return path; } }