i see two issues:
1) First u r calling listRoots, tht must print C:\
2) Secondly, u r not trying to get the iterate through the list of files that u got...
Let see ur code:
File[] filesOnComputer = File.listRoots();
this part shall give u the root of the directory structure (in most cases it would be C:, in case it is partioned it might also give D
then u will have to chk whether this is a directory, and if it is then u will have to call ur search function with little modification as:
public static void search(File f)
{
ArrayList arrayList = new ArrayList();
File[] files= f.listFiles(); // get all files under the direcrory
for(int index = 0; index < files.length; index++)
{
System.out.println ("here we are---"+files[index].getName());
arrayList.add(files[index].getName());
}
System.out.println (f.getName());
}
u might need to also call this recursively to see if the next selection is a file or a directory.
Try this :
public static void main(String[] args)
{
File[] filesOnComputer = File.listRoots();
{
ArrayList listOfFiles = new ArrayList();
System.out.println (filesOnComputer.length);
for(int index = 0; index < filesOnComputer.length; index++)
{
listOfFiles.add((File)filesOnComputer[index]);
if(filesOnComputer[index].isDirectory()){
System.out.println ("here we are-"+filesOnComputer[index].getPath());
search((File)listOfFiles.get(index));
}
else
System.out.println ("This is not the directory-"+filesOnComputer[index].getPath());
}
}
}
public static void search(File f)
{
ArrayList arrayList = new ArrayList();
File[] files= f.listFiles();
for(int index = 0; index < files.length; index++)
{
System.out.println ("here we are---"+files[index].getName());
arrayList.add(files[index].getName());
}
System.out.println (f.getName());
}