簡體   English   中英

如何使用jar cmmand類似於jar -tvf僅列出jar內的文件夾,將給出所有文件和目錄?

[英]How to list only folders inside jar using jar cmmand similar to jar -tvf will give all files and directory?

我的jar包含不同的文件夾,子文件夾和文件。 要列出和查看jar的內容,我可以使用jar -tvf jar_name 有沒有辦法用jar -tvf或類似的其他命令來僅列出jar內容內的目錄。

我看到jar有以下選項,但除了-t ,我找不到哪個可以幫助專門列出文件或文件夾。- -t選項不能一次全部列出。

jar Options:
    -c  create new archive
    -t  list table of contents for archive
    -x  extract named (or all) files from archive
    -u  update existing archive
    -v  generate verbose output on standard output
    -f  specify archive file name
    -m  include manifest information from specified manifest file
    -e  specify application entry point for stand-alone application
        bundled into an executable jar file
    -0  store only; use no ZIP compression
    -M  do not create a manifest file for the entries
    -i  generate index information for the specified jar files
    -C  change to the specified directory and include the following file

我需要加載jar文件,並在樹結構中顯示文件夾和文件。 什么是實現這種邏輯的最佳方法。

Jar是一個zip文件。 使用這個答案 或以編程方式回答1或此回答2

獲取文件列表(請參閱文檔)並grep以“ \\” <-結尾的行,您將獲得目錄列表。

命令行(Linux);

jar tf JAR_PATH | grep ".*/$"

Java代碼將目錄保存在jar文件中;

try {
    JarFile jarFile = new JarFile(JAR_PATH);
    Enumeration<JarEntry> paths = jarFile.entries();
    while (paths.hasMoreElements()) {
        JarEntry path = paths.nextElement();
        if (path.isDirectory()) {
            System.out.println(path.getName());
        }
    }
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM