This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes I/O - creating a directory vs. not creating a dir Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I/O - creating a directory vs. not creating a dir" Watch "I/O - creating a directory vs. not creating a dir" New topic
Author

I/O - creating a directory vs. not creating a dir

Derek Harper
Greenhorn

Joined: Aug 02, 2006
Posts: 25
Hi guys,

I'm currently experimenting with creating files and directories. I've learned that it's good practice to "play" with code in order to gain a better understanding of how something works or doesn't work.

Take a look at the following code:



Now when i compile the program, i expect an exception to occur because the call to "mkdir' has been purposely omitted. However, the code compiles fine. However, when i look in the 'bin' directory, the "dexDir" is not there.

My question is why didn't the program throw an exception? Is there something i did wrong or omitted from the code?

Thanks in advance.....
[ September 17, 2008: Message edited by: Derek Harper ]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

It does throw an exception, but your ignoring that:

If you put a "e.printStackTrace()" in there you'll see the error appearing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Derek Harper
Greenhorn

Joined: Aug 02, 2006
Posts: 25
Ahhh, so that's what i forgot to do.

You're exactly right because once i added the e.printStackTrace() to the code, i got the following:

java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:883)
at NoFileDirDemo.main(NoFileDirDemo.java:11)

Thanks Rob!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I/O - creating a directory vs. not creating a dir
 
Similar Threads
File's mkdir() method does not throw an exception?
working with files and directories
File I/O prior to Java 1.5
Creation of a new file throws IOException
What''s going on with file names??