public static String getFilenameFromString ( String filePath ) { String newPath = filePath ; int forwardInd = filePath . lastIndexOf ( "/" ) ; int backInd = filePath . lastIndexOf ( "\\" ) ; if ( forwardInd > backInd ) { newPath = filePath . substring ( forwardInd + 1 ) ; } else { newPath = filePath . substring ( backInd + 1 ) ; } // still original if no occurance of "/" or "\" return newPath ; }
Extracts the filename from a path .