Java File Extension Name Get getFileExtension(String filePath)

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

Description

get File Extension

License

Apache License

Declaration

public static String getFileExtension(String filePath) 

Method Source Code


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

import java.io.File;

public class Main {
    public static String getFileExtension(String filePath) {
        if (filePath == null || filePath.trim().length() == 0) {
            return filePath;
        }//from w ww.  jav  a2 s .  c o  m

        int extenPosi = filePath.lastIndexOf(".");
        int filePosi = filePath.lastIndexOf(File.separator);
        if (extenPosi == -1) {
            return "";
        }
        return (filePosi >= extenPosi) ? "" : filePath.substring(extenPosi + 1);
    }
}

Related

  1. getFileExtension(String filename)
  2. getFileExtension(String fileName)
  3. getFileExtension(String fileName)
  4. getFileExtension(String fileName)
  5. getFileExtension(String filePath)
  6. getFileExtension(String filePath)
  7. GetFileExtension(String fname)
  8. getFileExtension(String name)
  9. GetFileExtension(String path)