get File Extension Name from File - Java java.io

Java examples for java.io:File Extension Name

Description

get File Extension Name from File

Demo Code

//package com.java2s;
import java.io.File;
import java.util.regex.Pattern;

public class Main {
    public static String getExtension(File file) {
        String[] segs = file.toString().split(Pattern.quote("."));
        return segs[segs.length - 1];
    }//from   www  . j a  va2 s. co  m

    public static String getExtension(String filename) {
        String[] segs = filename.split(Pattern.quote("."));
        return segs[segs.length - 1];
    }
}

Related Tutorials