Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

WithoutBook Forum

Ques. How can I find Directories under a folder?

- How can I find Directories under a folder, please provide me a source code example.

Advance thanks.
Anand

Posted on Sep 28, 2010 by Anand
Ans.
import java.io.*;

public class FindDirectories
{ public static void main(String[] args)
{ if (args.length == 0) args = new String[] { ".." };

try
{ File pathName = new File(args[0]);
String[] fileNames = pathName.list();

for (int i = 0; i { File tf = new File(pathName.getPath(),
fileNames[i]);
if (tf.isDirectory())
{ System.out.println(tf.getCanonicalPath());
main(new String [] { tf.getPath() });
}
}
}
catch(IOException e)
{ System.out.println("Error: " + e);
}
}
}
Posted on Sep 28, 2010 by Arindam Ghosh

Ans. Now I know who the brainy one is, I’ll keep loiokng for your posts.
Posted on Jun 14, 2011 by Emmly

Enter your Answer

Name
Email Address
Answer
©2024 WithoutBook