Question: A description of the File class is available on Oracles Java Web site at http:// docs.oracle.com/javase/7/docs/api/java/io/File.html. To use this class you must import java.io.File. For

A description of the File class is available on Oracle’s Java Web site at http:// docs.oracle.com/javase/7/docs/api/java/io/File.html. To use this class you must import java.io.File. For this program the relevant methods of the File class are described below:

File (String The constructor takes a pathname and creates a File object pathname) corresponding to the file or directory with that pathname. String Returns the pathname of the File object, e.g., getAbsolute Path () C:\Papers\TermPaper.odt string getName () Returns the name of the File object, e.g., TermPaper.odt boolean Tests whether


Write the static recursive method String searchForFile(File currentFolder, String filename). The first parameter should be a File object that specifies the root folder to search for the file named filename. The method should recursively search all subfolders for the file and return the complete pathname to the first match. For example, if currentFolder is set to C:\ and filename is “foo.txt” then it might return “C:\Code\Stuff\foo.txt” if that is a valid pathname for the file. If there is no file with a matching name within the currentFolder then the method should return a blank string, “”.

File (String The constructor takes a pathname and creates a File object pathname) corresponding to the file or directory with that pathname. String Returns the pathname of the File object, e.g., getAbsolute Path () C:\Papers\TermPaper.odt string getName () Returns the name of the File object, e.g., TermPaper.odt boolean Tests whether the File object is a directory. isDirectory () File[] If the File object is a directory then this returns an array of File listFiles () objects corresponding to all the items within the directory.

Step by Step Solution

3.52 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer public static String searchForFileFile currentFolder String filename get list of all files in ... View full answer

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 Java An Introduction to Problem Solving and Progra Questions!