Java File Extension Name Get getFileExtension(File file)

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

Description

Get the file extension of a file.

License

Open Source License

Parameter

Parameter Description
file The file object to get the extension for.

Return

The file extension or null if none found.

Declaration

private static String getFileExtension(File file) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013//from  w w w .  j a  v a2s  .c  om
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Benjamin Klatt - initial API and implementation and/or initial documentation
 *******************************************************************************/

import java.io.File;

public class Main {
    /**
     * Get the file extension of a file.
     *
     * @param file
     *            The file object to get the extension for.
     * @return The file extension or null if none found.
     */
    private static String getFileExtension(File file) {
        String path = file.toString();
        if (path == null) {
            return null;
        }
        String fileExtension = path.substring(path.lastIndexOf('.') + 1);
        return fileExtension;
    }
}

Related

  1. getFileExtension(File file)
  2. getFileExtension(File file)
  3. getFileExtension(File file)
  4. getFileExtension(File file)
  5. getFileExtension(File file)
  6. getFileExtension(File file)
  7. getFileExtension(File file)
  8. getFileExtension(File file, boolean includeDot)
  9. getFileExtension(File file, boolean withDot)