Solved

list directory in jar files

Posted on 2001-07-17
1
176 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 47
sumHeights  challenge 17 59
topping3 challenge 14 48
Systems talking to each other 5 107
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now