java讀取jar文件

import java.io.*;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class TestReadJarFile {
    private static final String FILE_PATH =
            "D:\\minhq\\project\\tranfer_data\\target\\transfer_data-1.0-SNAPSHOT.jar";
    public static void main(String[] args) {
        try {
            readJarFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void readJarFile() throws IOException {
        JarFile localJarFile = new JarFile(new File(FILE_PATH));
        Enumeration<JarEntry> entries = localJarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry jarEntry = entries.nextElement();
            String innerPath = jarEntry.getName();
            if (innerPath.endsWith("MANIFEST.MF")) {
                InputStream inputStream = localJarFile.getInputStream(jarEntry);
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                String line = null;
                while (null != (line = bufferedReader.readLine())) {
                    System.out.println(line);
                }
            }
        }
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章