Is it possible to run a method based on an array of filenames? For example, I wish to create an array of all files within a given directory - which this question discusses - but I then wish to apply a method to all files/filenames within the array.
The reason for this is because I have 300 (soon-to-be 500) image files which I wish to perform a function on, and it is clearly ridiculous to have to write 300-500 separate instances of the same function in the main() method for many obvious reasons (also, the number of images is likely to increase in the future, which would definitely make this approach even more ludicrous).
I would therefore like to know if this can be done using an array to store the file names, and then using the file name from each array location 0-299 in order to perform the function on said image file.
Something like this:
Create array of FileNames;
For
all filenames 0-299 in array;
perform method(filename(0-299));
End for
I have already written the relevant code to perform the function, I just need to know if there is a way of achieving my goal in a much more efficient manner.
A simpler way of putting this is to ask how to run a method on all files (not sub-directories) within a given directory?
Many thanks.
System.out.print("Text");statement.