I have a folder containing 100000 files, and need to get 1000 files from this folder through random sampling. Are there any sample functions that I can use to sample from folder? In addition, how to copy the sampled files to another folder?
Share
Random selection could follow along the following lines
Essentially, you need to grab a list of the available files and the randomly pick through the list until you have enough of a sample. Check out
java.io.FileThere are plenty of examples of file copying over the net (and SO). If you’re really stuck you could have a look the IO Trail or Apache Commons IO which I believe has a utility class capable of coping files
UPDATED
As suggested by Andrew, you could simply shuffle the file list and pull the first 1000 elements…