• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

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

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 22656
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic