Originally posted by vivek gaur:
how do i write this recursive method .
please advice me technically.
Hmm, this sounds suspiciously like a homework assignment.
since a recursive method works by calling itself, in a general way, you write a method that lists the objects in a directory, examines each object in the list and, if the object represents a directory, calls itself again on that object, lists the objects in that directory, examines each object in the list, and if the object represents a directory, calls itself again ... and so forth. the tricky part is always that there must be a point of return, so that the recursion returns to the top when there are no more directories to process.
how does
java handle the recursive function, when it compiles the class? i believe that some 'c' compilers unroll the recursive function and turn it into standard loops because recursive functions can be extremely inefficient in use of resources when called directly. however, in terms of comprehensibility of the original source code, they are far more useful.
well, i went to google, my home-away-from-home, solver of many homework assignments, and typed in 'java list directory recursive' and got these pages in the top 7 results:
Java Practices: Recursive file listingJava Forums - How do I list directory contents?Java Programming, Solution to Programming Exercise Every time this routine finds a directory, it lists not just the name of the directory but also, recursively, the names of everything that it contains. ...
Java: Example - Recursive List Here is an example of listing files and directories recursively. ... i
Traversing the Files and Directories Under a Directory (Java ... so, my answer is,
you should start there. then, ask specific questions about the parts you don't understand and post the code that gives you problems.
thanks.
mp