logo CodeStepByStep logo

crawl

Language/Type: Java recursion file input
Related Links:

Write a recursive method named crawl that accepts a string for a file or directory name as a parameter and prints information about that file or directory. If the name represents a normal file, just print its name. If the name represents a directory, print its name and information about every file/directory inside it, indented by 4 spaces at each level. For example, the call of crawl("course") might print the following information about your course directory:

course
    handouts
        lecture-schedule.xls
        syllabus.doc
    homework
        1-gameoflife
            GameOfLife.zip
            life.h
            life.java

Show the files in a given directory sorted in alphabetical order. (You may want to use the Arrays.sort command to help you with this.)

Constraints: Your method must be recursive, though you may use a loop to help you as appropriate.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.