Java File Extension Name Extract getFileExtension(File path)

Here you can find the source of getFileExtension(File path)

Description

get File Extension

License

Open Source License

Declaration

public static String getFileExtension(File path) 

Method Source Code

//package com.java2s;
/*//w ww  .ja v  a2 s . c om
 * ====================================================================
 * Copyright (c) 2004-2012 TMate Software Ltd.  All rights reserved.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at http://svnkit.com/license.html
 * If newer versions of this license are posted there, you may use a
 * newer version instead, at your option.
 * ====================================================================
 */

import java.io.File;

public class Main {
    public static String getFileExtension(File path) {
        if (path == null)
            return null;
        return getFileNameExtension(path.getName());
    }

    public static String getFileNameExtension(String name) {
        if (name == null)
            return null;
        int dotInd = name.lastIndexOf('.');
        if (dotInd != -1 && dotInd != 0 && dotInd != name.length() - 1) {
            return name.substring(dotInd + 1);
        }
        return null;
    }
}

Related

  1. getFileExtension(File file)
  2. getFileExtension(File file)
  3. getFileExtension(File file)
  4. getFileExtension(File file, boolean includeDelimiter)
  5. getFileExtension(File fx)
  6. getFileExtension(final String fileName)
  7. getFileExtension(final String filenamePath)
  8. getFileExtension(String fileName)
  9. getFileExtension(String filename)