Here file.createNewFile() needs a try/catch block or need throws declaration in the method signature to compile where as file.isDirectory() is just fine.I expect file.isDirectory() to behave the same way as file.createNewFile() behaves.Can anyone explain this
Why would it throw an IOException if no I/O takes place? The method can throw an uncheckedSecurityException, which (obviously) is not subject to the same catch-or-declare requirement as the IOException thrown by the createNewFile() method.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.