Solved

list directory in jar files

Posted on 2001-07-17
1
178 Views
Last Modified: 2012-06-27
String[] fileNames = dir.list();

is used for normal folders.  How to put list of files in array for JAR files??
0
Comment
Question by:TLTEO
1 Comment
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 15 total points
ID: 6291231
Jar files are simply Zip files with a manifest. Here is one example of how to do this.

import java.util.zip.*;
import java.util.*;
import java.io.*;

public class ZipList {
    ZipFile _zipfile;

    public ZipList(File file) throws ZipException, IOException {
        _zipfile = new ZipFile(file);
    }

    public String[] list() {
        ArrayList list = new ArrayList(_zipfile.size());
        Enumeration enum = _zipfile.entries();
        while (enum.hasMoreElements()) {
            ZipEntry entry = (ZipEntry)enum.nextElement();
            list.add(entry.getName());
        }
        return (String[])list.toArray(new String[list.size()]);
    }
    public static void main(String[] args) throws Exception {
        ZipList zip = new ZipList(new File(args[0]));
        String[] names = zip.list();
        for (int i = 0; i < names.length; ++i) {
            System.out.println(names[i]);
        }

    }
}

Best regards,
Jim Cakalic
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 22
MySqlDump not dumping triggers 1 32
tomcat administrtor 12 48
Which non-HTML GUI front end to use with Java? 3 22
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question