/** * Returns <code>true</code> if file has extension. */ public static boolean hasExtension(String filename) { return indexOfExtension(filename) != -1; }
/** * Returns <code>true</code> if file has extension. */ public static boolean hasExtension(final String filename) { return indexOfExtension(filename) != -1; }
/** * Gets the extension of a filename. * <p> * This method returns the textual part of the filename after the last dot. * There must be no directory separator after the dot. * <pre>{@code * foo.txt --> "txt" * a/b/c.jpg --> "jpg" * a/b.txt/c --> "" * a/b/c --> "" * }</pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to retrieve the extension of. * @return the extension of the file or an empty string if none exists. */ public static String getExtension(String filename) { if (filename == null) { return null; } int index = indexOfExtension(filename); if (index == -1) { return StringPool.EMPTY; } else { return filename.substring(index + 1); } }
/** * Removes the extension from a filename. * <p> * This method returns the textual part of the filename before the last dot. * There must be no directory separator after the dot. * <pre>{@code * foo.txt --> foo * a\b\c.jpg --> a\b\c * a\b\c --> a\b\c * a.b\c --> a.b\c * }</pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to query, null returns null * @return the filename minus the extension */ public static String removeExtension(String filename) { if (filename == null) { return null; } int index = indexOfExtension(filename); if (index == -1) { return filename; } else { return filename.substring(0, index); } }
/** * Removes the extension from a filename. * <p> * This method returns the textual part of the filename before the last dot. * There must be no directory separator after the dot. * <pre>{@code * foo.txt --> foo * a\b\c.jpg --> a\b\c * a\b\c --> a\b\c * a.b\c --> a.b\c * }</pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to query, null returns null * @return the filename minus the extension */ public static String removeExtension(final String filename) { if (filename == null) { return null; } int index = indexOfExtension(filename); if (index == -1) { return filename; } else { return filename.substring(0, index); } }
/** * Gets the extension of a filename. * <p> * This method returns the textual part of the filename after the last dot. * There must be no directory separator after the dot. * <pre>{@code * foo.txt --> "txt" * a/b/c.jpg --> "jpg" * a/b.txt/c --> "" * a/b/c --> "" * }</pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to retrieve the extension of. * @return the extension of the file or an empty string if none exists. */ public static String getExtension(final String filename) { if (filename == null) { return null; } int index = indexOfExtension(filename); if (index == -1) { return StringPool.EMPTY; } else { return filename.substring(index + 1); } }
int lastExtensionIndex = indexOfExtension(filename);
int lastExtensionIndex = indexOfExtension(filename);
/** * Returns <code>true</code> if file has extension. */ public static boolean hasExtension(final String filename) { return indexOfExtension(filename) != -1; }
/** * Removes the extension from a filename. * <p> * This method returns the textual part of the filename before the last dot. * There must be no directory separator after the dot. * <pre>{@code * foo.txt --> foo * a\b\c.jpg --> a\b\c * a\b\c --> a\b\c * a.b\c --> a.b\c * }</pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to query, null returns null * @return the filename minus the extension */ public static String removeExtension(final String filename) { if (filename == null) { return null; } int index = indexOfExtension(filename); if (index == -1) { return filename; } else { return filename.substring(0, index); } }
/** * Gets the extension of a filename. * <p> * This method returns the textual part of the filename after the last dot. * There must be no directory separator after the dot. * <pre>{@code * foo.txt --> "txt" * a/b/c.jpg --> "jpg" * a/b.txt/c --> "" * a/b/c --> "" * }</pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to retrieve the extension of. * @return the extension of the file or an empty string if none exists. */ public static String getExtension(final String filename) { if (filename == null) { return null; } int index = indexOfExtension(filename); if (index == -1) { return StringPool.EMPTY; } else { return filename.substring(index + 1); } }
int lastExtensionIndex = indexOfExtension(filename);