Muhammad Waseem ullah Muhammad Waseem ullah - 1 year ago 89
Java Question

How to open folder and view properties of folder, in java?


File file=new File("folderName");
doesn't work?
folder name and path is valid. Same code is running for files but not for folders.

File file=new File("folderName");
System.out.println("Folder exists");
System.out.println("Folder doesn't exists");

For folder
always return false.

I can't use other libraries in my Assignment.

Answer Source

Most likely this is looking for "folderName" in the wrong place:

File file = new File("folderName");

That uses the current working directory, and it might be different than what you assume (depending on your environment, IDE, etc).

You can easily debug the issue using:


By the way, you should simplify if(file.exists() == true) to if(file.exists()).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download