List of utility methods to do File Extension Name Get
File | changeExtension(File file, String extensionNew) Trys to change file's extension to extensionNew. Check.arg().validFile(file); Check.arg().notBlank(extensionNew); if (extensionNew.contains(".")) throw new IllegalArgumentException("extensionNew = " + extensionNew + " contains a '.' char"); File parent = file.getParentFile(); String nameNew = getNameMinusExtension(file) + "." + extensionNew; File fileNew = new File(parent, nameNew); ... |
String | getExtension(File file) Returns the file's extension, defined here as the part of its name after the last '.' return getExtension(file, false, false);
|
String | getExtension(File file) get Extension int startIndex = file.getName().lastIndexOf(46) + 1; int endIndex = file.getName().length(); return file.getName().substring(startIndex, endIndex); |
String | getExtension(File file, boolean useFirstPeriod, boolean includePeriod) Returns the file's extension. Check.arg().notNull(file); String name = file.getName(); int indexPeriod = useFirstPeriod ? name.indexOf('.') : name .lastIndexOf('.'); if (indexPeriod == -1) return ""; if (!includePeriod) indexPeriod += 1; ... |
String | getExtension(String file) get Extension int extPos = file.lastIndexOf('.'); if (extPos != -1 && extPos > file.indexOf(File.separatorChar)) { return file.substring(extPos); return ""; |
String | getExtension(String filename) Return the file extension of the provided filename, or null if one does not exist.
if (Util.isBlank(filename)) { return null; if (filename.lastIndexOf('.') == -1) { return null; return filename.substring(filename.lastIndexOf('.') + 1); |
String | getExtensionName(String fileName) get Extension Name if ((fileName != null) && (fileName.length() > 0)) { int dot = fileName.lastIndexOf('.'); if ((dot > -1) && (dot < (fileName.length() - 1))) { return fileName.substring(dot + 1).toLowerCase(); return ""; |
String | getFileEx(String filePath) get File Ex String result = null; int index = filePath.lastIndexOf("."); if (index > -1) { result = filePath.substring(index + 1, filePath.length()); } else { result = "noEx"; return result; ... |
String | getFileExt(String fileFullName) get File Ext int dot = fileFullName.lastIndexOf("."); if ((dot > -1) && (dot < fileFullName.length() - 1)) { return fileFullName.substring(dot + 1); } else { return null; |
String | getFileExtByFileName(String fileName) get File Ext By File Name if (fileName == null) return ""; else { int idx = fileName.lastIndexOf("."); if (idx != -1) return fileName.substring(idx + 1); else return ""; ... |