Return to Snippet

Revision: 5064
at February 8, 2008 09:37 by pmatrasc


Updated Code
public static String getFileExtension(String fileName) {
        File tmpFile = new File(fileName);
        tmpFile.getName();
        int whereDot = tmpFile.getName().lastIndexOf('.');
        if (0 < whereDot && whereDot <= tmpFile.getName().length() - 2 ) {
            return tmpFile.getName().substring(whereDot+1);
        }    
        return "";
    }

Revision: 5063
at February 8, 2008 09:07 by pmatrasc


Initial Code
public static String getFileExtension(String fileName) {
        File tmpFile = new File(fileName);
        tmpFile.getName();
        int whereDot = tmpFile.getName().lastIndexOf('.');
        if (0 < whereDot && whereDot <= tmpFile.getName().length() - 2 ) {
            return tmpFile.getName().substring(0, whereDot+1);
        }    
        return "";
    }

Initial URL
blog.paolomatrascia.com

Initial Description


Initial Title
Extract the extension of a file  from a full pathname

Initial Tags
file, files, extension

Initial Language
Java