// getting the extension of a filename, (plain or including dirname) // This code is much faster than any regex technique. // filename without the extension String choppedFilename; // extension without the dot String ext; // where the last dot is. There may be more than one. int dotPlace = filename.lastIndexOf ( '.' ); if ( dotPlace >= 0 ) { // possibly empty choppedFilename = filename.substring( 0, dotPlace ); // possibly empty ext = filename.substring( dotPlace + 1 ); } else { // was no extension choppedFilename = filename; ext = ""; }