Question: USE JAVA Objective: To implement and invoke recursive methods in determining information from a file system directory. Description: This project consists of writing an application
USE JAVA
Objective: To implement and invoke recursive methods in determining information from a file system directory.
Description: This project consists of writing an application that invokes recursive methods to obtain information about a given file system directory. Specifically, your application should:
1.Prompt the user for the name of a directory.
1.If the name entered is a directory,
1.Display the number of files in it by invoking the countFiles() method, and
2.Display all the files in the given directory and all files within subdirectories by invoking the displayFiles() method, and
2.Otherwise, display a message stating the given name is not a directory.
2.Prompt the user for the name of a file (could be a directory), and display a message to indicate whether or not the given filename is found within the given directory (invoke the fileFound() for this).
The File class can be used to represent a file or a directory and obtain the properties for files and directories.
You will be defining the following recursive methods:
1. int countFiles (File file)
This method should recursively count the number of files (including subdirectories and files and subdirectories in the subdirectories, etc.) found in the given directory. Hint: The number of files in a directory can be defined recursively as follows:
countFiles (d) = countFiles (f1) + countFiles(f2) + + countFiles(fm) +
countFiles(d1) + countFiles(d2) + + countFiles (dn)
2. void displayFiles (File file)
This method should recursively display the names of files and directories (and files within subdirectories, etc.) in the given directory.
3. boolean fileFound(File file, File findFile )
This method should recursively determine if a given file (findFile) is found in the given directory (file)
please do in java
please do not write on paper as it is hard to read hand writing most times, and check to see if program actually works.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
