public static List < String > listAllMime ( String directory , String type ) { List < String > ret = new ArrayList <> ( ) ; try { // see if it's a URL or not URL url = new URL ( directory ) ; if ( url . getProtocol ( ) . equals ( "file" ) ) { directory = url . getFile ( ) ; } else if ( url . getProtocol ( ) . equals ( "jar" ) ) { return listJarMime ( url , null , null ) ; } else { throw new RuntimeException ( "Not sure what to do with this url. " + url . toString ( ) ) ; } } catch ( MalformedURLException ignore ) { } File d = new File ( directory ) ; if ( ! d . isDirectory ( ) ) throw new IllegalArgumentException ( "Must specify an directory" ) ; File [ ] files = d . listFiles ( ) ; if ( files == null ) return ret ; for ( File f : files ) { if ( f . isDirectory ( ) ) continue ; try { String mimeType = Files . probeContentType ( f . toPath ( ) ) ; if ( mimeType . contains ( type ) ) ret . add ( f . getAbsolutePath ( ) ) ; } catch ( IOException ignore ) { } } Collections . sort ( ret ) ; return ret ; }
Lists all files in the directory with an MIME type that contains the string type