OK, so i do have a perfectly good working code but im trying a different way and its bugging me why its not working. any help would be much appreciated. the program suppose to list all the available directories and then ask the user which directory he's searching for, takes the input and search for the directory. if the directory exist it will find it and list all the files in it and the path to it. if it can't find the directory it will throw a message or exception saying so.
Now it lists all the directories just fine and asks the user input but it wont go past that and thats where i'm stucked......
here's the code:
import java.io.File;
import java.util.Scanner;
import javax.swing.filechooser.*;
/**
*/
public class MyMain {
public static void main(String[] args) {
//String dir;
String keyWord = "";
Scanner keyboard = new Scanner(System.in);
File[] dir = File.listRoots();
//System.out.println("Please enter the key to root directory from the list below: "
/* FileSystemView.getFileSystemView().getHomeDirectory() + " " + FileSystemView.getFileSystemView().getRoots()[0] + " " +
System.getProperty("user.dir") + File.listRoots() */;
System.out.println("Available root directories in filesystem are : ");
for(int i=0 ; i < dir.length ; i++)
{
System.out.println(dir[i]);
}
keyWord = keyboard.nextLine();
System.out.println(" Please enter the directory to scan: ");
String path = keyboard.nextLine();
while(path != null){
if( rootDirectories.exists() == false){
System.out.println("Error: That directory does not exist. ");
break;
}
if (rootDirectories.canRead() = false){
System.out.println("Error, cannot read that directory. ");
break;
}
System.out.println("Directory is Valid. "); //test output
}
keyboard.close();
}
I know its incorrect but can someone give me an idea on how to correct it. thanks