List of utility methods to do File Extension Name Get
String | getSuffix(String f) get Suffix int idx = f.lastIndexOf('.'); if (idx > -1) { return f.substring(f.lastIndexOf('.') + 1); return null; |
boolean | hasExtension(String filename, String extension) Returns whether or not the provided filename has the provided extension. if (Util.isBlank(extension)) { return false; String fileExtension = getExtension(filename); if (Util.isBlank(fileExtension)) { return false; return fileExtension.equalsIgnoreCase(extension.replace(".", "")); ... |
int | indexOfExtension(String filename) index Of Extension if (filename == null) { return -1; int extensionPos = filename.lastIndexOf("."); int lastSeparator = filename.lastIndexOf("/"); return (lastSeparator > extensionPos ? -1 : extensionPos); |
boolean | isValidFileExtension(String extension) Checks if the extension is valid. for (int i = 0; i < extension.length(); i++) { char c = extension.charAt(i); if (!(Character.isDigit(c) || Character.isLetter(c) || c == '_')) { return false; return true; |
String | parseFileExtension(String filename) Parse the filename and return the file extension. if (filename == null) { return null; int pos = filename.lastIndexOf('.'); if (pos < 0 || (pos + 1) >= filename.length()) { return null; return filename.substring(pos + 1); ... |
String | parseFileExtension(String filename) Returns the extension of the given filename. String ext = null; if (filename != null) { int dot = filename.lastIndexOf('.'); if (dot > 0 && dot < filename.length()) { ext = filename.substring(dot + 1); return ext; ... |
String | removeExtension(String file) remove Extension int extPos = file.lastIndexOf('.'); if (extPos != -1 && extPos > file.indexOf(File.separatorChar)) { file = file.substring(0, extPos); return file; |
String | removeExtension(String s) Removes the path and extension from the input String separator = System.getProperty("file.separator"); String filename; int lastSeparatorIndex = s.lastIndexOf(separator); if (lastSeparatorIndex == -1) { filename = s; } else { filename = s.substring(lastSeparatorIndex + 1); int extensionIndex = filename.lastIndexOf("."); if (extensionIndex == -1) { return filename; return filename.substring(0, extensionIndex); |
String | getExtension(final String fileName) get Extension return fileName.substring(fileName.lastIndexOf(".") + 1) .toLowerCase(); |
String | getFileExtenSion(File file) get File Exten Sion String ex; String filename; try { filename = file.getName(); ex = filename.substring(filename.lastIndexOf(".") + 1); } catch (Exception e) { return ""; return ex.toLowerCase(Locale.getDefault()); |