集册 Java实例教程 获得清单财产

获得清单财产

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

370
获得清单财产

/** from 
nowjava.com**/

//package com.nowjava;


import java.io.IOException;

import java.io.InputStream;


import java.util.jar.JarFile;

import java.util.jar.Manifest;


import java.util.zip.ZipEntry;


public class Main {

    public static String getManifestProperty(String jarFilename,

            String manifestKey) throws IOException {

        try (JarFile file = new JarFile(jarFilename)) {

            ZipEntry entry = file.getEntry("META-INF/MANIFEST.MF");

            InputStream is = file.getInputStream(entry);
            /*
            NowJava.com 提供
            */

            if (is == null) {

                return "(No META-INF/MANIFEST.MF file)";

            }

            return readManifestProperty(is, manifestKey);

        }

    }


    public static String getManifestProperty(

            ClassLoader clContainingManifest, String manifestKey)

            throws IOException {

        // Check Manifest file for generated build number

        InputStream is = clContainingManifest

                .getResourceAsStream("META-INF/MANIFEST.MF");

        return readManifestProperty(is, manifestKey);

    }


    private static String readManifestProperty(InputStream is,

            String manifestKey) throws 
展开阅读全文