Java tutorial
//package com.java2s; public class Main { public static String getBeforeExtension(String path, String insert) { if (getFileExtension(path).equals("") || getFileExtension(path) == null) { return null; } StringBuffer sb = new StringBuffer(path); int index = path.lastIndexOf("."); sb.insert(index, insert); return sb.toString(); } public static String getFileExtension(String file) { return file.substring(file.lastIndexOf(".") + 1, file.length()); } }