Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { /** * Ensures that a filename always ends with the file name extension * @param name * @return */ public static String getFileNameWithExtension(String name, String fileNameExtension) { int len = fileNameExtension.length(); String substr = name.substring(Math.max(0, name.length() - len)); if (!substr.equals(fileNameExtension)) { name = name + fileNameExtension; } return name; } }