Java File Extension Name Extract getFileExtension(File f)

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

Description

get File Extension

License

Apache License

Declaration

private static String getFileExtension(File f) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {
    private static String getFileExtension(File f) {
        String fileName = f.getName();
        String fileExtension = fileName;

        int lastPos = fileName.lastIndexOf('.');

        if (lastPos > 0 && lastPos < (fileName.length() - 1)) {
            fileExtension = fileName.substring(lastPos + 1).toLowerCase();
        }/* w w w.j  ava  2 s.co m*/

        return fileExtension;
    }

    public static String getFileExtension(String f) {
        String fileName = f;
        String fileExtension = fileName;

        int lastPos = fileName.lastIndexOf('.');

        if (lastPos > 0 && lastPos < (fileName.length() - 1)) {
            fileExtension = fileName.substring(lastPos + 1).toLowerCase();
        }

        return fileExtension;
    }
}

Related

  1. extractFileExtension(String filename)
  2. extractFileExtension(String fileName)
  3. extractFileExtension(String filePath)
  4. extractFileExtension(String path)
  5. extractFileExtensionFromPath(String path)
  6. getFileExtension(File file)
  7. getFileExtension(File file)
  8. getFileExtension(File file)
  9. getFileExtension(File file)