Question: Hi I have a folder containing many files , is there a way if i can just filter out or delete the files (which are

Hi I have a folder containing many files , is there a way if i can just filter out or delete the files (which are not in the list) according to a list of Strings which is a substring of the file names.

List of String,

List fileListNames = Arrays.asList("bus_ticket","driver_trips","train_ticket");

the filenames inside the folder are like this

ABC_bus_device_20230118_20230119.xml

ABC_bus_ticket_20230118_20230119.xml

AET_driver_trips_20230118_20230119.xml

I only want this two files in the folder

ABC_bus_ticket_20230118_20230119.xml

AET_driver_trips_20230118_20230119.xml

Is there a filter out using Java code, please help thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!