• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Derek Harper
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does throw an exception, but your ignoring that:

If you put a "e.printStackTrace()" in there you'll see the error appearing.
 
Derek Harper
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic