-2

i know this is a duplicate question of: list all files from directories and subdirectories in Java but i have a problem with displaying sub directories of a directory. I already have a folder class:

class Folder
{
bool isFile;
String folderName;
list<Folder> subFolders;
}

Now using this class i need to display the list of sub directories and files within a specified folder...

i tried using this code:

class FCheck
{
public static void main(String args[])
{
Folder obj=new Folder();
obj.folderName="C:\hello";
if(obj.folderName.isDirectory())
{

}

what should i do inside the if condition loop ?? i need to use the <list> folder subfolders data!

Community
  • 1
  • 1
Rebooting
  • 2,762
  • 11
  • 47
  • 70
  • 1
    No, you don't need to *use* it - you need to *create* it, which you'd do with `File.listFiles`. Which part of that is causing you problems? (Note that your current code wouldn't compile for various reasons. It helps if you can present *real* code.) – Jon Skeet Nov 27 '12 at 07:28
  • the only thing i am not able to understand that why listsubFolders is given ?? – Rebooting Nov 27 '12 at 07:38

1 Answers1

0
public class ListFoldersAndFiles {
    public static void main(String[] args)
    {
        ListFoldersAndFiles obj1= new ListFoldersAndFiles();
        obj1.go();
    }

    public void go()
    {
        File [] fileNames;
        File file=new File("c:/test");
        if(file.isDirectory()){
            fileNames= file.listFiles();
            for(File temp:fileNames){
                System.out.println(temp.getName());
            }
        }
    }
}
Fathah Rehman P
  • 8,401
  • 4
  • 40
  • 42