CowZow CowZow - 2 months ago 8
Java Question

How do you iterate over entries in a zip file in random order in Java?

I'm working on a machine learning project and I have 10,000 training files stored in a zip. I want to train my model on each file in the zip file, and I heard it is preferable to randomize the order of your training data if you train over your full dataset multiple times. This project is done in Java.

So I was wondering if it is possible to iterate over entries in a

ZipFile
in a random order in Java? Here is the API I referred to: https://docs.oracle.com/javase/7/docs/api/java/util/zip/ZipFile.html

Answer

Iterate the zip file using zipFile.entries() and add the zip entries to an ArrayList<ZipEntry>.

Randomize that list by calling Collections.shuffle(list).

You can now simply iterate the randomized list and call zipFile.getInputStream(zipEntry).

Comments