Dev-Ria
Dev-Ria

Reputation: 329

What happens when Java is deleting, editing and altering files in folder?

I have a java app that uses

File folder = new File("filesFolder);
File[] listOfFiles = folder.listFiles();

    for(int i = 0; i < listOfFiles.length; i++){//check files and edit}

to go through each and every file in a folder with some specific instructions. What would happen if it is looping through the folder and new files are added? Would it process these new files or would they skipped?

This folder is constantly updated with new files to be processed.

Upvotes: 1

Views: 71

Answers (1)

Henry Keiter
Henry Keiter

Reputation: 17168

New files (added after you call listFiles()) would be skipped. Additionally, if any files were deleted before they were processed, you'd get an Exception when you tried to read them.

This is because your array listOfFiles does not change. It's just an array of File objects. It's not somehow linked to the filesystem, unless you implement that yourself.

Upvotes: 2

Related Questions