Szabi Tóth
Szabi Tóth

Reputation: 1

How to get a random file out of a folder?

selectedFiles.addAll(getMiscFiles("before"));

This code choose all the files from the folder, but I need to choose one random file only. I couldn't figure out how to do, so every advice is very welcome.

Upvotes: 0

Views: 58

Answers (1)

Barzana Panajotova
Barzana Panajotova

Reputation: 46

If getMiscFiles() returns a list you can: selectedFiles.addAll(getMiscFiles("before").get(0)); This will get the first file from the list and add it to selectedFiles

Upvotes: 1

Related Questions