private static String getExtension ( String fileName ) { // play it safe and get rid of any fragment id // that might be there int length = fileName . length ( ) ; int newEnd = fileName . lastIndexOf ( ' ' ) ; if ( newEnd == - 1 ) { newEnd = length ; } int i = fileName . lastIndexOf ( ' ' , newEnd ) ; if ( i != - 1 ) { return fileName . substring ( i + 1 , newEnd ) ; } else { // no extension, no content type return null ; } }
Get extension of file without fragment id