How to get file extension in java code example

Get file extension in java code example

public static String getFileExtension(String filePath)
    {
        File f = new File(filePath);
        String name = f.getName();
        int k = name.lastIndexOf(".");
        String ext = null;
        if(k != -1)
            ext = name.substring(k + 1, name.length());
        return ext;
    }

Comments

  1. Sir , Bahut acha post hai well sir aap AJAX ke bare post kyo nahi karta.

    Prashant Kumar

    ReplyDelete
  2. Sir, Ek aur baat puchni hai AJAX ka use kar ke "select Country dropdown automatically State name in dropdown & City Name in dropdown.

    Prashant Kumar

    ReplyDelete
  3. But it is also good to check if '.' is last symbol in filename

    ReplyDelete

Post a Comment

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

How to capture finger prints in java

Shallow Copy Deep Copy Java example