return the true extension're like extension - Java java.io

Java examples for java.io:File Extension Name

Introduction

The following code shows how to return the true extension're like extension

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String target = "java2s.com";
        String extension = "com";
        System.out.println(isFileExtension(target, extension));
    }//www  .  j  a v a 2  s  .  co m

    /** Period (.) */
    public static final String PERIOD = ".";

    /**
     * return the true extension're like {@code extension}.<br/>
     * 
     * @param target
     *            Investigation target string
     * @param extension
     *            Extension(Not including the dot ("."))
     * @return true:Extension match false:Extension mismatch
     */
    public static boolean isFileExtension(String target, String extension) {
        if (target.endsWith(PERIOD + extension)) {
            return true;
        }
        return false;
    }
}

Related Tutorials