diff --git a/src/fr/devinsy/util/FileTools.java b/src/fr/devinsy/util/FileTools.java index c33c125..47b30cd 100644 --- a/src/fr/devinsy/util/FileTools.java +++ b/src/fr/devinsy/util/FileTools.java @@ -24,6 +24,45 @@ import java.net.URL; */ public class FileTools { + /** + * + * + * @param fileName + * Source. + * + * @return Extension value or null. + */ + public static String addBeforeExtension(final String fileName, final String addition) + { + String result; + + if (fileName == null) + { + result = null; + } + else if (addition == null) + { + result = fileName; + } + else + { + // + int separatorIndex = fileName.lastIndexOf('.'); + + // + if (separatorIndex > 0) + { + result = fileName.substring(0, separatorIndex) + addition + fileName.substring(separatorIndex); + } + else + { + result = fileName + addition; + } + } + + // + return result; + } /** * @@ -49,20 +88,7 @@ public class FileTools { // String sourceFileName = file.getAbsolutePath(); - int separatorIndex = sourceFileName.lastIndexOf('.'); - - // - String targetFileName; - if (separatorIndex > 0) - { - targetFileName = sourceFileName.substring(0, separatorIndex) + addition + sourceFileName.substring(separatorIndex); - } - else - { - targetFileName = sourceFileName + addition; - } - - // + String targetFileName = addBeforeExtension(sourceFileName, addition); result = new File(targetFileName); }