Solved

list directory in jar files

Posted on 2001-07-17
1
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

733 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