0

First the user browses for the zip file containing their Java project using a JFileChooser which is limited to .zip extension only.

Then I want all the file paths to be stored as strings in an array.

Browse... button:

btnBrowse.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        int returnVal = fileChooser.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File zip = fileChooser.getSelectedFile();
            // This is where the I need help.
        }
    }
});

So my array will be like this:

[path\to\java\file, path\to\java\file, path\to\java\file, path\to\java\file]

Can someone help me out here?

Ciphor
  • 732
  • 4
  • 11
  • 25

2 Answers2

1

use this method to get list of selected files.

File[] zipFiles = fileChooser.getSelectedFiles();

and then

for (File file : zipFiles )
  {
      System.out.println(file .getAbsoluteFile()); // will print path
      // Add to array here
  }
Jabir
  • 2,776
  • 1
  • 22
  • 31
  • I don't think you understood what I wanted to achieve, this would just print the path of each zip file, I want to get the paths of the files WITHIN the zip file. – Ciphor Apr 02 '13 at 15:24
  • Look at following link http://stackoverflow.com/questions/11468163/list-zip-direcotries-without-extracting-java – Jabir Apr 02 '13 at 15:58
  • 1
    This[http://www.javaworld.com/community/node/8362] tutorial has a detailed explanation of how to handle zip files including listing files in it – Jabir Apr 02 '13 at 16:00
  • Great resource! I now have an ArrayList with all the file names in. So I'm very close to what I want but I'm finding it hard to explain :) – Ciphor Apr 02 '13 at 16:09
0

You might want to check the java.util.zip package out. It provides classes for reading and writing the standard ZIP and GZIP file formats.

sha1
  • 153
  • 7
mthmulders
  • 9,483
  • 4
  • 37
  • 54