private static String makeBackupFilename(String filename, String toInsert) { int lastSlash = filename.lastIndexOf(System.getProperty("file.separator")); if (lastSlash == -1) { JConfig.log().logDebug("Filename has no separators: " + filename); lastSlash = 0; } int firstDot = filename.indexOf('.', lastSlash); if (firstDot == -1) { JConfig.log().logDebug("Filename has no dot/extension: " + filename); firstDot = filename.length(); } return filename.substring(0, firstDot) + '-' + toInsert + filename.substring(firstDot); }