Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

create a file without directory

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create a file in this path C:\\test\\A\\B\\myfile.txt. But the directory A, B and file 'myfile.txt' all are not existed.

Do I have easiest way to directly create that file, instead of creating directory A, B first ?

Thanks.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://download-llnw.oracle.com/javase/6/docs/api/java/io/File.html#mkdirs()

The documentation is your friend.
 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But make sure you call that method on the parent file. If you call it on your current File object then you will create a folder with that name, and you can't create a file with the same name again until you remove the folder.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic