Muhammad Waseem ullah Muhammad Waseem ullah - 4 months ago 24
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.


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()).