Java File Extension Name Get getFileExtension(String filename)

Here you can find the source of getFileExtension(String filename)

Description

get File Extension

License

Open Source License

Parameter

Parameter Description
filename a parameter

Declaration

public static String getFileExtension(String filename) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004-2010 Sunil Kamath (IcemanK).
 * All rights reserved.//ww  w.ja  v a2s  .  co  m
 * This program is made available under the terms of the Common Public License
 * v1.0 which is available at http://www.eclipse.org/legal/cpl-v10.html
 *
 * Contributors:
 *     Sunil Kamath (IcemanK) - initial API and implementation
 *******************************************************************************/

import java.io.*;

public class Main {
    public static String getFileExtension(File file) {
        String name = file.getName();
        return getFileExtension(name);
    }

    /**
     * @param filename
     * @return
     */
    public static String getFileExtension(String filename) {
        if (filename != null) {
            int n = filename.lastIndexOf('.');
            if (n >= 0) {
                return filename.substring(n + 1);
            }
        }
        return null;
    }
}

Related

  1. getFileExtension(final File file)
  2. getFileExtension(final File file)
  3. getFileExtension(final String file)
  4. getFileExtension(final String fullName)
  5. getFileExtension(String file)
  6. getFileExtension(String fileName)
  7. getFileExtension(String filename)
  8. getFileExtension(String fileName)
  9. getFileExtension(String fileName)