0

首先,用户使用仅限于 .zip 扩展名的 JFileChooser 浏览包含其 Java 项目的 zip 文件。

然后我希望将所有文件路径作为字符串存储在数组中。

浏览...按钮:

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.
        }
    }
});

所以我的数组将是这样的:

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

有人可以帮我吗?

4

2 回答 2

1

使用此方法获取选定文件的列表。

File[] zipFiles = fileChooser.getSelectedFiles();

进而

for (File file : zipFiles )
  {
      System.out.println(file .getAbsoluteFile()); // will print path
      // Add to array here
  }
于 2013-04-02T13:13:27.130 回答
0

您可能想检查java.util.zip包裹。它提供了用于读写标准ZIPGZIP文件格式的类。

于 2013-04-02T12:57:08.253 回答