Sandeep Jindal Sandeep Jindal - 2 months ago 28
Java Question

File.mkdir or mkdirs return false - Reason?

Why file.mkdir is returning false?

Google indicates that there could be several reasons (e.g. security, permissions, pathname, etc).

My questions:


  1. How to find the exact reason of returning false?

  2. If security/permissions is a reason, then why is SecurityException not thrown?


Answer

If security/permissions is a reason, then why is SecurityException NOT thrown (which is mentioned in javadoc)?

A SecurityException is thrown when you don't have JVM-level permission to do something, not OS-level

Is there a way to find the exact reason why of returning false?

No, AFAIK. The only way to know would be to check the permissions on the directory yourself or make sure it doesn't exist before calling them.

Comments