List of utility methods to do File Mime Type
String | detectFileType(String location) This function detects the file type of a file at the given location. String sanitizedLocation = location.replaceFirst("^/(.:/)", "$1"); Path filePath = Paths.get(sanitizedLocation); return Files.probeContentType(filePath); |
String | getFileType(String fileName) Determine a file type String fileType = null; File file = new File(fileName); try { if (file.isDirectory()) return "dir"; fileType = Files.probeContentType(file.toPath()); if (fileType == null) { int index = fileName.lastIndexOf('.'); ... |
String | getImageType(File file) get Image Type return getFileType(file).split("/")[1]; |
String | getMime(File file) get Mime try { return Files.probeContentType(file.toPath()); } catch (IOException e) { e.printStackTrace(); return ""; |
String | getMimeType(File file) get Mime Type String mimetype = null; try { mimetype = Files.probeContentType(file.toPath()); } catch (IOException ex) { if (mimetype == null) { mimetype = "unknown"; return mimetype; |
String | getMimeType(String fileName) get Mime Type try { return Files.probeContentType(Paths.get(fileName)); } catch (IOException e) { return "application/octet-stream"; |
String | getType(File file) This methods returns a type according to the file try { String contentType = Files.probeContentType(Paths.get(file.getAbsolutePath())); if (contentType != null) { return contentType; } catch (Exception ignore) { String fileName = file.getName(); ... |
boolean | isMP3(File file) Checks if is mp3. try { Path filepath = Paths.get(file.getAbsolutePath()); String contentType = Files.probeContentType(filepath); if (contentType.equals(MP3_MEDIA_TYPE)) return true; } catch (IOException e) { System.err.println("Error while detecting media type"); return false; |
boolean | isValidImage(File file) is Valid Image if (!file.exists()) { return false; String type = Files.probeContentType(file.toPath()); switch (type) { case "image/jpeg": return isValidJpeg(file); case "image/png": ... |