Java File Extension Name Get GetFileExtension(String path)

Here you can find the source of GetFileExtension(String path)

Description

Get File Extension

License

Open Source License

Declaration

public static String GetFileExtension(String path) 

Method Source Code

//package com.java2s;
/*//from   ww  w  . j  a  v  a2s .c  o m
 * This is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute
 * it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by
 * Sam Hocevar. See http://www.wtfpl.net/ for more details.
 */

public class Main {
    public static String GetFileExtension(String path) {
        String extension = "";

        if (path != null && path.length() > 0) {
            int idx = path.lastIndexOf('.');
            if (idx >= 0) {
                int lastSlashIdx = path.lastIndexOf(java.io.File.separatorChar);

                if (idx > lastSlashIdx) {
                    extension = path.substring(idx + 1);
                }
            }
        }

        return extension;
    }
}

Related

  1. getFileExtension(String filePath)
  2. getFileExtension(String filePath)
  3. getFileExtension(String filePath)
  4. GetFileExtension(String fname)
  5. getFileExtension(String name)