Question: In class Q2 from the provided starter files, you will find the following method stub: public static ArrayList findWithSuffix(String sDirectoryPath, String sSuffix, String sExtension) This
In class Q2 from the provided starter files, you will find the following method stub:
public static ArrayList findWithSuffix(String sDirectoryPath, String sSuffix, String sExtension)
This method is intended to be a recursive Java method for going through the given directory and related sub-directories and finding all those files with has given suffix in the file name and the file also has the provided extension. The method will return an ArrayList of all File objects relating to those files. Note that you can use ArrayList.add to add another ArrayList to an existing one.
Preform the following tasks in class Q2:
1 Get the directory path to work with from the user through command line argument
2 Display appropriate messages in case of file related errors, if applicable and encountered
3 Complete the logic of the findWithSuffix method
4 Call the findWithSuffix method and print the absolute file path of each file returned. The output should have one file path per line
//Starter file Q2.java is given below
package midterm1; import java.io.File; import java.util.ArrayList; public class Q2 { public static void main(String []args){ // directory path must be captured from command line argument // invoke the findWithSuffix method // display the absolute path of each file fetched using the findWithSuffix method // the display must be having path displayed as one per line } public static ArrayList findWithSuffix(String sDirectoryPath, String sSuffix, String sExtension) { //Replace with code that // fetches from the provided directory and sub-directories of sDirectoryPath // all the files ending with provided sSuffix in the name and // also has the extension specified by sExtension // do not forget to replace with appropriate return value return null; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
