From 8ecd4c57cd92383ec309ac6467c764ec71900d11 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Tue, 29 Oct 2013 15:17:20 +0100 Subject: [PATCH] Add getExtension method with String parameter. --- src/fr/devinsy/util/FileTools.java | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/fr/devinsy/util/FileTools.java b/src/fr/devinsy/util/FileTools.java index ad5f1fd..4fddf29 100644 --- a/src/fr/devinsy/util/FileTools.java +++ b/src/fr/devinsy/util/FileTools.java @@ -114,10 +114,35 @@ public class FileTools } else { - int separatorIndex = file.getName().lastIndexOf('.'); + result = getExtension(file.getName()); + } + + // + return result; + } + + /** + * Get the extension of a file. + * + * @param file + * Source. + * + * @return Extension value or null. + */ + public static String getExtension(final String fileName) + { + String result; + + if (fileName == null) + { + result = null; + } + else + { + int separatorIndex = fileName.lastIndexOf('.'); if (separatorIndex > 0) { - result = file.getName().substring(separatorIndex + 1).toLowerCase(); + result = fileName.substring(separatorIndex + 1).toLowerCase(); } else {