Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing to a file whose entire path does not exist  RSS feed

 
Aaron Dsouza
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Does any one know how to write to a file that does not exist. The file path will be something like this C:\MyDir1\MyDir2\file.txt and even MyDir1 and MyDir2 do not exist.

Thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

There's a "mkdirs()" method in java.io.File which you could use to ensure that the directories existed, and then write to the file after.
 
Aaron Dsouza
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the reply. It really helped .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!