I am trying to implement a function
which by using the Breadth First Search it finds all files with a relative path of searchPath
I have written down this code:
I expected it to output "diskLocation\\" then exit but it continuously prints out the files of the Java File(directory) specified by the diskLocation String and I dont understand why?Am I not removing it off the
Java:
public void calc(String searchPath,String diskLocation )
I have written down this code:
Java:
ArrayDeque<String>searchedFiles = new ArrayDeque<>();
searchedFiles.add(diskLocation);
while(!searchedFiles.isEmpty())
{
for(String i:searchedFiles)
{
System.out.println(i);
File f = new File(i);
if(f.isFile())
{
if(f.getPath()==searchPath)
{
foundFiles.add(i);
}
}
try{
var files = f.listFiles();
while(files!=null) {
for (File fl : files) {
System.out.println(fl.getCanonicalPath());
}
}
}
catch(Exception e)
{
}
searchedFiles.remove(i);
}
}
}
searchedFiles dequeue?What is happening?