aspose file tools
The moose likes Beginning Java and the fly likes doubt regarding file handling Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "doubt regarding file handling" Watch "doubt regarding file handling" New topic
Author

doubt regarding file handling

abin joy
Ranch Hand

Joined: Jul 29, 2008
Posts: 35
File file=new File("myfile.txt");

file.createNewFile()
file.isDirectory()

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
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1407

Why would it throw an IOException if no I/O takes place?
The method can throw an unchecked SecurityException, 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.
Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98
file.createNewFile is modifying the file system while file.isDirectory is only checking the status of the file system.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: doubt regarding file handling
 
Similar Threads
doubt in few questions
create file in servlet
Accessing files, detemining if they exist...
how sort a array of files and directories.. ?
Listing Subdirectories