集册 Java实例教程 如果给定资源是zip、jar或war文件,则返回true。

如果给定资源是zip、jar或war文件,则返回true。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

453
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
如果给定资源是zip,jar或war文件,则返回true。
/**
 * 时 代 J a v a - nowjava.com 提 供 
**/

//Licensed under the Apache License, Version 2.0 (the "License");

//package com.nowjava;


public class Main {

    public static void main(String[] argv) throws Exception {

        String resource = "nowjava.com";

        System.out.println(isSupported(resource));

    }


    /**

     * The suffixes of the files to support.

     */

    public static final String[] SUPPORTED_FILES = new String[] { ".zip",

            ".jar", ".war" };


    /**

     * Returns true if the given {@code resource} is either a zip, jar or war file.

     */

    public static boolean isSupported(String resource) {

        int idx = resource.lastIndexOf('.');

        if (resource.length() == idx + 4) {

            for (int i = 0; i < SUPPORTED_FILE
展开阅读全文